Sub Test3()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 5
LSearchRow = 5
'Start copying data to row 2 in Sheet3 (row counter variable)
LCopyToRow = 2
While Len(Range("Y" & CStr(LSearchRow)).Value) > 0
'If value in column Y = "84312570", copy entire row to Sheet3
If Range("Y" & CStr(LSearchRow)).Value = "84312570" Then
'Select row in MasterList to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet3 in next row
Sheets("Sheet3").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to MasterList to continue searching
Sheets("MasterList").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A5
Application.CutCopyMode = False
Range("A5").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
這會在列Y中查找特定值,並將相應信息的整行移動到各個工作表。根據搜索條件移動特定列
我有兩個問題。
首先,有沒有辦法指定只移動到單個工作表的某些列信息,而不是移動整行?
其次,有沒有一種方法可以僅基於Y列中的數字序列的最後4位數來提取信息?例如,上面我想要拉列Y中匹配* 2570的所有行。
這似乎也拉出來的特定列到新工作表工作。一直在做一點修補,但它的確有竅門。感謝您的幫助。 – Jon