#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counter

Looping through code, I would use the following:

Dim Counter As Integer

For Counter = 1 To 10
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter


Now, assume that I only want the counter to do this on some predefine
rows. How do I then tell the Counter to only loop through thes
specified integers (example = rows 1,5,8).

I have tried the following, which doesnt work.

For Counter = 1,5,8
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter

How do I phrase the "For counter.." part?

Thanks for the hel

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Counter

Hi,

Inside your loop, use the Select Case "counter"
Regards,

Jean-Yves

from help
Using Select Case Statements


Use the Select Case statement as an alternative to using ElseIf in
If...Then...Else statements when comparing one expression to several
different values. While If...Then...Else statements can evaluate a different
expression for each ElseIf statement, the Select Case statement evaluates an
expression only once, at the top of the control structure.

In the following example, the Select Case statement evaluates the
performance argument that is passed to the procedure. Note that each Case
statement can contain more than one value, a range of values, or a
combination of values and comparison operators. The optional Case Else
statement runs if the Select Case statement doesn't match a value in any of
the Case statements.

Function Bonus(performance, salary)
Select Case performance
Case 1
Bonus = salary * 0.1
Case 2, 3
Bonus = salary * 0.09
Case 4 To 6
Bonus = salary * 0.07
Case Is 8
Bonus = 100
Case Else
Bonus = 0
End Select
End Function

"JonoB " wrote in message
...
Looping through code, I would use the following:

Dim Counter As Integer

For Counter = 1 To 10
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter


Now, assume that I only want the counter to do this on some predefined
rows. How do I then tell the Counter to only loop through these
specified integers (example = rows 1,5,8).

I have tried the following, which doesnt work.

For Counter = 1,5,8
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter

How do I phrase the "For counter.." part?

Thanks for the help


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Counter

Sub test()
Dim arr As Variant, i As Long

arr = Array(1, 5, 8)
For i = LBound(arr) To UBound(arr)
Range("A" & arr(i)).Value = arr(i)
Next

End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"JonoB " wrote in message
...
Looping through code, I would use the following:

Dim Counter As Integer

For Counter = 1 To 10
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter


Now, assume that I only want the counter to do this on some predefined
rows. How do I then tell the Counter to only loop through these
specified integers (example = rows 1,5,8).

I have tried the following, which doesnt work.

For Counter = 1,5,8
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter

How do I phrase the "For counter.." part?

Thanks for the help


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Counter

You could use an array

aryCntr = Array(1,5,8)

For i = LBound(aryCntr,1) To UBound(aryCntr,1)
Counter = aryCntr(i)
Range("A" & Counter).Counter
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"JonoB " wrote in message
...
Looping through code, I would use the following:

Dim Counter As Integer

For Counter = 1 To 10
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter


Now, assume that I only want the counter to do this on some predefined
rows. How do I then tell the Counter to only loop through these
specified integers (example = rows 1,5,8).

I have tried the following, which doesnt work.

For Counter = 1,5,8
Range("A" & Counter).Select
ActiveCell = Counter
Next Counter

How do I phrase the "For counter.." part?

Thanks for the help


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counter

Many thanks Rob abd Bob

Just what I was looking for

--
Message posted from http://www.ExcelForum.com

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
How do i set up a counter? Bulldog21 Excel Discussion (Misc queries) 2 July 23rd 08 02:12 PM
Add A Day Counter EisPanzer Excel Discussion (Misc queries) 3 May 9th 07 01:24 AM
counter Haza Excel Discussion (Misc queries) 2 January 20th 06 08:30 PM
Counter Sdbenn90 Excel Discussion (Misc queries) 4 January 9th 06 11:43 AM
Max value in Do While counter ChrisG[_4_] Excel Programming 7 September 24th 03 01:36 AM


All times are GMT +1. The time now is 04:09 AM.

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"