Setting up an incremented Variable name

  • Thread starter Thread starter David Looney
  • Start date Start date
D

David Looney

I'm looping through a named range looking for cells whose value matches a
criteria. For each of those cells that match, I want to assign the cells
value to an "incremented" variable (Var1, Var2, Var3, etc.)



Counter = 1

Set rng = range("myRange")



1 For each cell in rng

2 If cell.value = "whatever"

3 Var & counter = cell.value

4 End if

5 Next cell





I cant get line 3 to work (Var1, Var2, Var3)



Thanks
 
You should be using arrays if you want to do that kind of thing. You are best
off reading up on arrays in vba.
 
Dave, Let me know if this helps:

Dim strVar(20) As String
Set rng = Range("myRange")

For Each cell In rng
If cell.value = "whatever"
strVar(i) = cell.Value
i = i + 1
End If
Next cell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top