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
 
Back
Top