Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting up an incremented Variable name

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Setting up an incremented Variable name

You should be using arrays if you want to do that kind of thing. You are best
off reading up on arrays in vba.


"David Looney" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Setting up an incremented Variable name

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


"Blue Aardvark" wrote:

You should be using arrays if you want to do that kind of thing. You are best
off reading up on arrays in vba.


"David Looney" wrote:

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
incremented numbering tourpro Excel Discussion (Misc queries) 4 April 21st 08 09:24 PM
How can a single cell be incremented? i.e. N=N+1 Remel Excel Discussion (Misc queries) 1 September 21st 05 08:19 PM
setting object variable [email protected] Excel Programming 2 May 13th 05 07:28 PM
Setting variable = to sheet name Jeff Armstrong Excel Programming 2 July 26th 04 08:57 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM


All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"