我有以下vba代码在以下列中查找出现"0":
For Each c In Range("B:B")
If c.Value = "0" Then
MsgBox "0 found at " & (c.Address)
End If
Next c
Run Code Online (Sandbox Code Playgroud)
如何修改代码,以便当它在B6处找到"0"时,它会显示C7?即.它显示与找到"0"的那个对角相邻的单元格.
Ale*_*x P 24
您可以使用 Offset
MsgBox "0 found at " & c.Offset(1,1).Address
Run Code Online (Sandbox Code Playgroud)
该Offset
物业属于这种形式Offset(row, column)
.例子:
Range("B6").Offset(0,0) //refers to cell B6
Range("B6").Offset(1,0) //move one row down (B7)
Range("B6").Offset(0,1) //move one column to the right (C6)
Range("B6").Offset(-1,0) //move one row up (B5)
Range("B6").Offset(0,-1) //move one column to the left (A6)
Run Code Online (Sandbox Code Playgroud)
怎么样:
MsgBox "0 found at " & Cells(c.Row + 1, c.Column + 1)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
36361 次 |
最近记录: |