Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Confused with variable

Greetings,

I have a named range called WorksheetNames. I want to cycle through them and
do a set of operations. I wrote the following simplified code, however, I
can't seem to get the Name to work in the Worksheets() convention.

Dim Name As Range

For Each Name in Range("WorsheetNames")
Worksheet(Name).Cells(1,1).Value = "No Flag Set"
Other code
Next Name

Would someone explain what I am missing?

Thanks,
Ray


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Confused with variable

Ray,

"Name" is an object type in Excel/VBA, so you shouldn't use it as
a variable name. Also, you need Worksheets to be plural, not
singular. Try something like


Dim Rng As Range
For Each Rng In Range("WorksheetNames")
Worksheets(Rng.Value).Cells(1,1).Value = "No Flag Set"
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Ray Batig" wrote in message
ink.net...
Greetings,

I have a named range called WorksheetNames. I want to cycle

through them and
do a set of operations. I wrote the following simplified code,

however, I
can't seem to get the Name to work in the Worksheets()

convention.

Dim Name As Range

For Each Name in Range("WorsheetNames")
Worksheet(Name).Cells(1,1).Value = "No Flag Set"
Other code
Next Name

Would someone explain what I am missing?

Thanks,
Ray




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Confused with variable

1. "WorksheetNames" is mispelled.

2. The correct syntax is Worksheets(Name)

3. Also, since Name is a reserved VBA word, it may be better to use another
name (no pun intended) for your cell variable.

--

Vasant


"Ray Batig" wrote in message
ink.net...
Greetings,

I have a named range called WorksheetNames. I want to cycle through them

and
do a set of operations. I wrote the following simplified code, however, I
can't seem to get the Name to work in the Worksheets() convention.

Dim Name As Range

For Each Name in Range("WorsheetNames")
Worksheet(Name).Cells(1,1).Value = "No Flag Set"
Other code
Next Name

Would someone explain what I am missing?

Thanks,
Ray




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Confused with variable

Thanks Chip! Now I understand. The .Value was the crux.

Ray
Chip Pearson wrote in message
...
Ray,

"Name" is an object type in Excel/VBA, so you shouldn't use it as
a variable name. Also, you need Worksheets to be plural, not
singular. Try something like


Dim Rng As Range
For Each Rng In Range("WorksheetNames")
Worksheets(Rng.Value).Cells(1,1).Value = "No Flag Set"
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Ray Batig" wrote in message
ink.net...
Greetings,

I have a named range called WorksheetNames. I want to cycle

through them and
do a set of operations. I wrote the following simplified code,

however, I
can't seem to get the Name to work in the Worksheets()

convention.

Dim Name As Range

For Each Name in Range("WorsheetNames")
Worksheet(Name).Cells(1,1).Value = "No Flag Set"
Other code
Next Name

Would someone explain what I am missing?

Thanks,
Ray






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
Now I'm Really Confused doss04 New Users to Excel 5 October 14th 08 04:38 AM
confused. Please help. doss04 Excel Discussion (Misc queries) 9 October 4th 08 10:38 PM
Very confused.... mizterbusy Excel Discussion (Misc queries) 1 September 24th 06 06:44 AM
confused,please help shrutikhurana Excel Discussion (Misc queries) 1 February 3rd 06 12:32 PM
confused... keepitcool Excel Programming 0 September 22nd 03 09:29 AM


All times are GMT +1. The time now is 03:57 AM.

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

About Us

"It's about Microsoft Excel"