假設我想在整個作業表中找到包含字串“XYXY”的單元格(比如說它在單元格(100,35)中)并在下一列中更改它旁邊的單元格的值(例如單元格(100, 36))。如何有效地做到這一點?
我知道
Set CellPV = ActiveSheet.Cells.Find(What:="XYXY", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
它確實有效地找到了單元格,但沒有顯示位置/范圍;當我使用 時MsgBox(CellPV),它給了我單元格的值,而不是它在作業表中的位置。
如何才能做到這一點?
uj5u.com熱心網友回復:
您不需要知道CellPV作業表上的地址。
只需使用Range.Offset:
If Not CellPV Is Nothing Then 'Test if Find was successful
CellPV.Offset(,1).Value = "foo"
End If
如果你真的想知道cellPV地址,那么:
MsgBox CellPV.Address 'no parentheses here
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/437786.html
上一篇:從日期VBA獲取整數值
