PC Review


Reply
Thread Tools Rate Thread

Cycle through a list

 
 
Basil
Guest
Posts: n/a
 
      13th Jan 2010
Hi,

I have a more comprehensive query below but don't really have the time to
wait for a comprehensive answer.

Could you please help me with going through a list in VBA?

I have a named range and the first column has a list of countries. I want to
go through this list and do an action for each country. Can you please help
with how to do this? I've tried things like application.index(myrange,,1)
with no luck, and don't know the appropriate way to cycle through once I have
that too.

I have a fuller query ('Creating multiple pivot report at run time') with no
replies below. If that is a step too far, help with the abive would be
greatly appreciated.

Many thanks,

Basil
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      13th Jan 2010


Try something like the following:

Dim R As Range
For Each R In Range("MyRange").Columns(1).Cells
R.EntireRow.Cells(1,"F") = 1234
Next R

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]


On Tue, 12 Jan 2010 16:35:01 -0800, Basil
<(E-Mail Removed)> wrote:

>Hi,
>
>I have a more comprehensive query below but don't really have the time to
>wait for a comprehensive answer.
>
>Could you please help me with going through a list in VBA?
>
>I have a named range and the first column has a list of countries. I want to
>go through this list and do an action for each country. Can you please help
>with how to do this? I've tried things like application.index(myrange,,1)
>with no luck, and don't know the appropriate way to cycle through once I have
>that too.
>
>I have a fuller query ('Creating multiple pivot report at run time') with no
>replies below. If that is a step too far, help with the abive would be
>greatly appreciated.
>
>Many thanks,
>
>Basil

 
Reply With Quote
 
Basil
Guest
Posts: n/a
 
      13th Jan 2010
Thanks Chip, I can't get it to work. It keeps throwing an error on the first
row (I've copied your exact code and also tried specifically referencing the
worksheet of the named range too... nothing.

I'll try and be more specific. I have a named range called 'Country_Data'
(25 columns wide, variable row height) on a sheet called 'Country Analysis'.
In column one is the country name.

I want to click a button and the code to go through the first column and
show me a msgbox for each country in that first column with the country name
displayed. Once all the countries have had a message box displayed, it will
stop.

I'm using Excel 2003.

Thanks!

Basil

"Chip Pearson" wrote:

>
>
> Try something like the following:
>
> Dim R As Range
> For Each R In Range("MyRange").Columns(1).Cells
> R.EntireRow.Cells(1,"F") = 1234
> Next R
>
> Cordially,
> Chip Pearson
> Microsoft MVP 1998 - 2010
> Pearson Software Consulting, LLC
> www.cpearson.com
> [email on web site]
>
>
> On Tue, 12 Jan 2010 16:35:01 -0800, Basil
> <(E-Mail Removed)> wrote:
>
> >Hi,
> >
> >I have a more comprehensive query below but don't really have the time to
> >wait for a comprehensive answer.
> >
> >Could you please help me with going through a list in VBA?
> >
> >I have a named range and the first column has a list of countries. I want to
> >go through this list and do an action for each country. Can you please help
> >with how to do this? I've tried things like application.index(myrange,,1)
> >with no luck, and don't know the appropriate way to cycle through once I have
> >that too.
> >
> >I have a fuller query ('Creating multiple pivot report at run time') with no
> >replies below. If that is a step too far, help with the abive would be
> >greatly appreciated.
> >
> >Many thanks,
> >
> >Basil

> .
>

 
Reply With Quote
 
Basil
Guest
Posts: n/a
 
      13th Jan 2010
The problem seems to be in Range("MyRange").

If I type in a reference like "A7:F34" it works fine, but not when
referencing the named range. I've tried adding Sheets("Country Analysis") or
Worksheets("Country Analysis") beforehand but it threw up a different error.

"Chip Pearson" wrote:

>
>
> Try something like the following:
>
> Dim R As Range
> For Each R In Range("MyRange").Columns(1).Cells
> R.EntireRow.Cells(1,"F") = 1234
> Next R
>
> Cordially,
> Chip Pearson
> Microsoft MVP 1998 - 2010
> Pearson Software Consulting, LLC
> www.cpearson.com
> [email on web site]
>
>
> On Tue, 12 Jan 2010 16:35:01 -0800, Basil
> <(E-Mail Removed)> wrote:
>
> >Hi,
> >
> >I have a more comprehensive query below but don't really have the time to
> >wait for a comprehensive answer.
> >
> >Could you please help me with going through a list in VBA?
> >
> >I have a named range and the first column has a list of countries. I want to
> >go through this list and do an action for each country. Can you please help
> >with how to do this? I've tried things like application.index(myrange,,1)
> >with no luck, and don't know the appropriate way to cycle through once I have
> >that too.
> >
> >I have a fuller query ('Creating multiple pivot report at run time') with no
> >replies below. If that is a step too far, help with the abive would be
> >greatly appreciated.
> >
> >Many thanks,
> >
> >Basil

> .
>

 
Reply With Quote
 
Basil
Guest
Posts: n/a
 
      13th Jan 2010
Found a workaround. The problem was that the reference to the range was not
working. I believe this is because it was a dynamic range (defined using the
offset formula). So I set a fixed range and dealt with blank cells through
the code.

"Basil" wrote:

> The problem seems to be in Range("MyRange").
>
> If I type in a reference like "A7:F34" it works fine, but not when
> referencing the named range. I've tried adding Sheets("Country Analysis") or
> Worksheets("Country Analysis") beforehand but it threw up a different error.
>
> "Chip Pearson" wrote:
>
> >
> >
> > Try something like the following:
> >
> > Dim R As Range
> > For Each R In Range("MyRange").Columns(1).Cells
> > R.EntireRow.Cells(1,"F") = 1234
> > Next R
> >
> > Cordially,
> > Chip Pearson
> > Microsoft MVP 1998 - 2010
> > Pearson Software Consulting, LLC
> > www.cpearson.com
> > [email on web site]
> >
> >
> > On Tue, 12 Jan 2010 16:35:01 -0800, Basil
> > <(E-Mail Removed)> wrote:
> >
> > >Hi,
> > >
> > >I have a more comprehensive query below but don't really have the time to
> > >wait for a comprehensive answer.
> > >
> > >Could you please help me with going through a list in VBA?
> > >
> > >I have a named range and the first column has a list of countries. I want to
> > >go through this list and do an action for each country. Can you please help
> > >with how to do this? I've tried things like application.index(myrange,,1)
> > >with no luck, and don't know the appropriate way to cycle through once I have
> > >that too.
> > >
> > >I have a fuller query ('Creating multiple pivot report at run time') with no
> > >replies below. If that is a step too far, help with the abive would be
> > >greatly appreciated.
> > >
> > >Many thanks,
> > >
> > >Basil

> > .
> >

 
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
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 in VBA azidrane Microsoft Excel Discussion 3 15th Mar 2006 09:51 PM
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.