【发布时间】:2019-05-10 05:50:14
【问题描述】:
我在 VBA 中有一个小项目,并坚持以下主题。
我需要选择从搜索值到 H 列中第一个空单元格的范围。
所选范围应如下所示
我在 A 列中搜索了特定值,如果找到它,则将其设置为范围内的第一个单元格。 (有效)
然后我需要找到范围内的最后一个单元格,即最后一列中的第一个空单元格。
这是我发现并尝试使用的
Sub Button()
Dim StringToFind As String
StringToFind = Application.InputBox("Enter string to find", "Find string")
Worksheets("SS19").Activate
ActiveSheet.Range("A:A").Select
Set cell = Selection.Find(What:=StringToFind, After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
cell.Select
With Worksheets("SS19")
Set rr = .Range(ActiveCell, .Cells(.Rows.Count, "H").End(xlUp))
With rr
rr.Parent.Range(.Cells(1, "A"), .Cells(.Rows.Count, "H").End(xlUp).Offset(1, 0)).Select
End With
End With
If cell Is Nothing Then
Worksheets("SS19").Activate
MsgBox "String not found"
End If
我尝试在先前选择的范围内搜索第一个空单元格,因此它不会搜索整个列,但它不起作用。
【问题讨论】:
-
这将有助于确保图像中的行号和列字母可见。