ante011
ante011

Reputation: 99

Step down in a Column and find a match - vba

I would like to use a for each and go trough a column (.range(A1:A500)) in Excel to find my specific value.

For example Start in A1 and go down through the cells, if i find something called X then stop and insert a row above. After this i want to exit my for each.

Ive searched but i cant find a solution that will work for me. =/

Im grateful for any help in this case.

Upvotes: 0

Views: 194

Answers (1)

Harassed Dad
Harassed Dad

Reputation: 4704

You can loop through each cell in your range and find a match like this:

 Dim r as range
 For each r in range("a1:a500")
     If r = X then
        'found it
         if r.row>1 then
         rows(r.row-1).insert
         else
          rows(1).insert
         end if
         exit for
     end if
 Next r

Upvotes: 1

Related Questions