PC Review


Reply
Thread Tools Rate Thread

Cycle through a list in VBA

 
 
azidrane
Guest
Posts: n/a
 
      15th Mar 2006
Hey, I need to just do a For...Next loop to cycle through a predefined
list (or range really).

Sort of..

For every cell in this list
Check the text in list against a variable
perform action
Next in list


that sort of thing. I just don't konw what to call the list, cell,
anything..

Thanks in advance.

 
Reply With Quote
 
 
 
 
Nick Hodge
Guest
Posts: n/a
 
      15th Mar 2006
azidrane

Something like

Sub Iterate()
Dim myCell as Range
For Each myCell in Range("A1:A100")
'do stuff here
Next MyCell
End Sub

You can use Selection instead of the range dsignation whih will iterate the
cells under the selection

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
(E-Mail Removed)HIS


"azidrane" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hey, I need to just do a For...Next loop to cycle through a predefined
> list (or range really).
>
> Sort of..
>
> For every cell in this list
> Check the text in list against a variable
> perform action
> Next in list
>
>
> that sort of thing. I just don't konw what to call the list, cell,
> anything..
>
> Thanks in advance.
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Mar 2006
Something like:

Option Explicit
Sub TestMe01()

Dim myRng As Range
Dim myCell As Range
Dim myString As String

myString = "WhatDoYouWantToCompare"

Set myRng = Worksheets("sheet1").Range("a1:A1000")

For Each myCell In myRng.Cells
With myCell
If LCase(.Value) = LCase(mystr) Then
'do something
Else
'do something else or not
End If
End With
Next myCell

End Sub




If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

azidrane wrote:
>
> Hey, I need to just do a For...Next loop to cycle through a predefined
> list (or range really).
>
> Sort of..
>
> For every cell in this list
> Check the text in list against a variable
> perform action
> Next in list
>
> that sort of thing. I just don't konw what to call the list, cell,
> anything..
>
> Thanks in advance.


--

Dave Peterson
 
Reply With Quote
 
azidrane
Guest
Posts: n/a
 
      15th Mar 2006
Thanks to both Dave and Nick for this.

Cheers!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cycle through a list Basil Microsoft Excel Programming 4 13th Jan 2010 05:36 PM
Automatically cycle through a list of Parameters KWhamill Microsoft Access VBA Modules 5 10th Jul 2008 10:38 PM
cycle thru list adding date JohnE Microsoft Access Form Coding 4 29th Feb 2008 02:11 AM
Cycle through a list (Part 2) Pete Microsoft Excel Programming 2 19th Dec 2003 07:34 PM
Cycle trhough a list of names Pete Microsoft Excel Programming 3 19th Dec 2003 02:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:18 AM.