美好的一天,
我正在寻找帮助来解决我的问题。我想在A列中找到一个包含文本" Grand Total"的单元格。查找是关键字,因为它有时可能会输入A14,或A12或A20。找到文本后,我想选择该单元格,然后选择B列中的下一个单元格。假设文本在A14中找到,然后选择A14和B14。
这样,我想继续编辑格式为font = bold,填充颜色和字体颜色(我很快就会想出来)。
我似乎无法找到能够帮助我的代码,所以我感谢任何帮助。下面是我发现的代码,但它似乎不适用于我。此链接的信用额度为:How to select a range of rows using two variables in VBA
Dim Consultant1 As Integer, Consultant2 As Integer
Dim ConsultantRange As Range
Dim rngFind As Range
Set rngFind = Columns("A:A").Find(What:="Grand Total", After:=Range("A1"), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not rngFind Is Nothing Then
Consultant1 = rngFind.row + 1
End If
Set rngFind = Columns("A:A").Find(What:="Grand Total", After:=Range("A1"), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not rngFind Is Nothing Then
Consultant2 = rngFind.row - 1
End If
If Consultant1 > 0 And Consultant2 > 0 Then
Set ConsultantRange = Range(Cells(Consultant1, 2), Cells(Consultant2, 2))
With ConsultantRange.Selection.Font.Bold = True
End With
End If
答案 0 :(得分:2)
怎么样:
Sub qwerty()
Dim rngFind As Range
Set rngFind = Range("A:A").Find(What:="Grand Total", After:=Range("A1"))
rngFind.Resize(1, 2).Select
End Sub