-1

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.

  • 2
    Yes that's possible in VBA – Tim Williams Oct 18 '16 at 18:24
  • can you indicate me some functions/properties helpful to achieve this result? of course it would take only a couple of names, just to point me in the right documentation – Jacopo Mansani Oct 18 '16 at 18:31
  • 1
    It would help to explain a little more exactly what you want to do, along with a small set of sample data – Tim Williams Oct 18 '16 at 18:34
  • 1
    It sounds like you're looking for the [Range.Find](https://msdn.microsoft.com/en-us/library/office/ff839746.aspx) method – tigeravatar Oct 18 '16 at 18:35
  • I recommend checking [How to Ask](http://stackoverflow.com/help/how-to-ask). Technically, Tim answered your question. To know more, we need to know what you're attempting to do. In VBA especially, there are many ways to do the same thing - but start with Find, perhaps Match, or Search. Also, check out how to use Variables and [how to avoid `.Select`](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) for working directly with the data. – BruceWayne Oct 18 '16 at 18:40
  • I should be able to make a search vertically, into a column that can be situated in different cells because once again to the document should be included new columns "in the middle". Given this task comes my question, which was specifically to see if it was possible to identify a column from the content of his first cell, for example, which in my case will be populated with a specific string. – Jacopo Mansani Oct 18 '16 at 18:41
  • Index, Match functions (Application), Offset method of range object, Application.GoTo or Select (if you want a literal "move"), etc. – David Zemens Oct 18 '16 at 20:20

1 Answers1

0

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
user3598756
  • 28,893
  • 4
  • 18
  • 28