我試圖編寫一個宏,它將在列E
和F
上進行過濾。如果兩個標準都滿足,它會將整行復制到新工作表。Excel宏不工作
這裏是我到目前爲止,但我不能得到它的工作...
Sub carving()
'482
SearchForString "482", "A01"
SearchForString "482", "A02"
SearchForString "482", "A03"
SearchForString "482", "A04"
'483
SearchForString "483", "A01"
SearchForString "483", "A02"
SearchForString "483", "A03"
SearchForString "483", "A04"
'484
SearchForString "484", "A01"
SearchForString "484", "A02"
SearchForString "484", "A03"
SearchForString "484", "A04"
'485
SearchForString "485", "A01"
SearchForString "485", "A02"
SearchForString "485", "A03"
SearchForString "485", "A04"
'482E
SearchForString "485", "A01"
SearchForString "485", "A02"
SearchForString "485", "A03"
SearchForString "485", "A04"
'482F
SearchForString "485", "A01"
SearchForString "485", "A02"
SearchForString "485", "A03"
SearchForString "485", "A04"
End Sub
Sub SearchForString(ColE, ColF)
'Dim LSearchRow As Long
Dim shtSearch As Worksheet
Dim shtCopyTo As Worksheet
Dim rw As Range
'LSearchRow = 2 'Start search in row 2
Set shtSearch = Sheets("example")
Set shtCopyTo = Sheets("test")
Dim LSearchRow As Integer
For LSearchRow = 2 To 30000
If Len(shtSearch.Cells(LSearchRow, 1).Value) > 0 Then
Set rw = shtSearch.Rows(LSearchRow)
If rw.Cells(7).Value = ColE And rw.Cells(6).Value = ColF Then
rw.Copy shtCopyTo.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
'Exit Do '? you say there's only one result to find
End If
End If
Next LSearchRow
End Sub
任何幫助,將不勝感激。
什麼錯誤信息你好嗎?您可以通過逐句通過調試器中的代碼(當光標位於代碼窗格中時使用F8鍵)來隔離導致問題的行。 – chuff
'LSearchRow = 2' 中的行開始搜索2 集shtSearch =表( 「例如」) 集shtCopyTo =表( 「測試」) 昏暗LSearchRow作爲整數 對於LSearchRow = 2至30000 如果len(shtSearch .Cells(LSearchRow,1)。價值)> 0然後 集RW = shtSearch.Rows(LSearchRow) 如果rw.Cells(5)。價值=科爾和rw.Cells(6)。價值= ColF然後 RW .Copy shtCopyTo.Cells(Rows.Count,1).End(xlUp).Offset(1,0) 'Exit Do'?你說只有一個結果找到 End If End If Next LSearchRow – user1588191