简体   繁体   中英

In Excel-VBA Is it possible to move in a column (or row, or cell) based solely on the content of another cell?

I wanted to know if t's possible not to use only the spatial references (for example, "Column A", "cell D3") but instead be able to realize a macro to move, for example, in the fourth row of a column in which the first cell contains the word "cat" for example. I do not know if I was clear in my question, in case I wasn't just ask for further clarification.

to "... move, for example, in the fourth row of a column in which the first cell contains the word "cat"" you may use:

Rows(1).Find(What:="cat",LookAt:=xlWhole, LookIn:=xlValues).Offset(3).Select

What above would throw an error if no first row cell value is "cat"

To handle such a situation:

Dim found As Range
Set found = Rows(1).Find(What:="cat",LookAt:=xlWhole, LookIn:=xlValues)
If Not found Is Nothing Then found.Offset(3).Select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM