我有以下宏应该在Col D中搜索,选择包含我的字母的行' b'。
为了使事情更加清晰,例如,我想选择整个行,其中' stack'发生在A栏。
Sub SelectRowsb()
Dim z As Range
Dim rngb As Range
For Each z In Intersect(ActiveSheet.UsedRange, Columns("D"))
If z = "b" Then
If rngb Is Nothing Then Set rngb = z.EntireRow
Set rngb = Union(rngb, z.EntireRow)
End If
Next z
rngb.Select
End Sub
我得到了运行时错误' 13'类型不匹配。在if z =" b"然后
任何解决此问题的提示都将受到赞赏。
编辑~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~修改代码到目前为止
Sub selectRowsB()
Dim varRange As String
Dim varRow As Long
varRange = ""
For varRow = 1 To ThisWorkbook.Sheets("sheet1").Range("A65000").End(xlUp).Row
If ThisWorkbook.Sheets("sheet1").Range("A" & varRow).Value = "stack" Then
If varRange = "" Then
varRange = ThisWorkbook.Sheets("sheet1").Range("A" & varRow).EntireRow.Address
Else
varRange = varRange & "," & ThisWorkbook.Sheets("sheet1").Range("A" & varRow).EntireRow.Address
End If
End If
Next
If varRange <> "" Then
ThisWorkbook.Sheets.Range(varRange).Select
End If
End Sub
编辑~~~~~~~~~~~~~~~~~~~~修改代码v2
Sub test()
Dim varRange As String
Dim varRow As Long
varRange = ""
For varRow = 1 To ThisWorkbook.Sheets("Sheet1").Range("A65000").End(xlUp).Row
If ThisWorkbook.Sheets("Sheet1").Range("A" & varRow).Value = "insert_job" Then
If varRange = "" Then
varRange = ThisWorkbook.Sheets("Sheet1").Range("A" & varRow).EntireRow.Address
Else
varRange = varRange & "," & ThisWorkbook.Sheets("Sheet1").Range("A" & varRow).EntireRow.Address
End If
End If
Next
If varRange <> "" Then
ThisWorkbook.Sheets("Sheet1").Range(varRange).Select
End If
End Sub
答案 0 :(得分:0)
Sub test()
Dim varRange As String
Dim varRow As Long
varRange = ""
For varRow = 1 To ThisWorkbook.Sheets("Sheet1").Range("A65000").End(xlUp).Row
If ThisWorkbook.Sheets("Sheet1").Range("A" & varRow).Value = "stack" Then
If varRange = "" Then
varRange = ThisWorkbook.Sheets("Sheet1").Range("A" & varRow).EntireRow.Address
Else
varRange = varRange & "," & ThisWorkbook.Sheets("Sheet1").Range("A" & varRow).EntireRow.Address
End If
End If
Next
If varRange <> "" Then
ThisWorkbook.Sheets("Sheet1").Range(varRange).Select
End If
End Sub
道歉,刚刚登录,因为它让我烦恼,这段代码经过测试,在我的机器上正常工作