0
我有一個代碼,用於搜索第1行中的文本字符串。沒有問題。VBA在行中查找文本1.如果大於零,則在下面的行中複製並粘貼
問題
當文本中找到我需要的宏搜索列的值大於零,如果找到複製整個行並粘貼到表2。所以我沒有成功。
請參見下面的代碼:
Private Sub btnUpdateEntry_Click()
Dim StringToFind As String
Dim i As Range
StringToFind = Application.InputBox("Enter string to find", "Find string")
Worksheets("Skills Matrix").Activate
ActiveSheet.Rows(1).Select
Set cell = Selection.Find(What:=StringToFind, After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
For Each i In cell
If i.Value > 0 Then
i.Select
ActiveCell.Range("1:1").EntireRow.Select
Selection.Copy
Sheets("Sheet2").Range("A65000").End(xlUp).Offset(1, 0).PasteSpecial
End If
Next i
If cell Is Nothing Then
Worksheets("Data").Activate
MsgBox "String not found"
End If
End Sub
謝謝。
謝謝你。但我收到類型不匹配錯誤@SJR – James
在哪一行?是否有些單元格不包含數字?我修改了上面的代碼,所以再試一次。 – SJR
其運行時錯誤13.它沒有在一條線上扯上。搜索到的文字是字符串 – James