有条件地搜索单元格值VBA



我有以下问题:我写了一点vba来搜索单元格中的某个值(这个值可以在不同的行中,但总是在同一列中(,然后取右边的值。我的代码似乎没有错误,但也什么都没做。。。

这是我的:

Dim bottomCell As Range
Dim offsetCell As Range
With Sheets("Spółka")
Set bottomCell = .Cells.Find(what:="Wykreślona z KRS?")
Set offsetCell = bottomCell.Offset(0, 1)
End With
If offsetCell.Value = "TRUE" Then
MsgBox "Spółka wykreślona z KRS"
End If

因此,如果单元格im右边的值等于"0",则逻辑将显示带有一些消息的窗口;TRUE";。现在,代码似乎正在搜索,但没有显示任何内容。。。

提前感谢

Alex

请用下一种方法试试:

Sub testFindCells()
Dim bottomCell As Range, offsetCell As Range, shSp As Worksheet

Set shSp = Sheets("Spólka")
Set bottomCell = shSp.UsedRange.Find("Wykreslona z KRS?", , xlValues)

If Not bottomCell Is Nothing Then
Set offsetCell = bottomCell.Offset(0, 1)
Debug.Print offsetCell.Address
If CBool(offsetCell.Value) = True Then
MsgBox "Spólka wykreslona z KRS"
End If
Else
MsgBox "Wykreslona z KRS?" & " coluld not be found..."
End If
End Sub

最新更新