Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Macro that uses range names

I am looking to create a simple macro. I have created some range names,
example is page1 all the way to page10. I want to copy these ranges to
another worksheet. The problem is my macro is only good if I know how many
range pages that I will actually need. I want to know how I can create a
loop that will work for 1 page or 100 pages.
--
Mr Speedy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro that uses range names

Here is a way to loop over names and to also display the count of names:

Sub NameIt()
Dim n As Name
For Each n In ActiveWorkbook.Names
MsgBox (n.Name & Range(n.Name).Address)
Next
MsgBox (ActiveWorkbook.Names.Count)
End Sub

--
Gary''s Student - gsnu200825


"speedy" wrote:

I am looking to create a simple macro. I have created some range names,
example is page1 all the way to page10. I want to copy these ranges to
another worksheet. The problem is my macro is only good if I know how many
range pages that I will actually need. I want to know how I can create a
loop that will work for 1 page or 100 pages.
--
Mr Speedy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Macro that uses range names

Besides evoking the Range object, you can also get the address directly from
the Name object itself...

MsgBox n.Name & " " & n.RefersToRange.Address

Also, the parentheses are not required when calling the MsgBox function like
it was a subroutine.

--
Rick (MVP - Excel)


"Gary''s Student" wrote in message
...
Here is a way to loop over names and to also display the count of names:

Sub NameIt()
Dim n As Name
For Each n In ActiveWorkbook.Names
MsgBox (n.Name & Range(n.Name).Address)
Next
MsgBox (ActiveWorkbook.Names.Count)
End Sub

--
Gary''s Student - gsnu200825


"speedy" wrote:

I am looking to create a simple macro. I have created some range names,
example is page1 all the way to page10. I want to copy these ranges to
another worksheet. The problem is my macro is only good if I know how
many
range pages that I will actually need. I want to know how I can create a
loop that will work for 1 page or 100 pages.
--
Mr Speedy


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro that uses range names

Do you mean that the macro crashes if you specify 100 pages but there
are only 15 pages? Use error trapping.

On Error GoTo Label01
[here use the x100 loop that works]
Label01:
End Sub

IIRC the "Label01:" has to start in column 1. You cannot indent it.

Fred Holmes

On Sun, 11 Jan 2009 06:37:01 -0800, speedy
wrote:

I am looking to create a simple macro. I have created some range names,
example is page1 all the way to page10. I want to copy these ranges to
another worksheet. The problem is my macro is only good if I know how many
range pages that I will actually need. I want to know how I can create a
loop that will work for 1 page or 100 pages.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro that uses range names

By pages, do you mean printed pages or are you referring to worksheets.
There can be many pages on a single worksheet. The worksheets are contained
in a workbook.

For printed pages on Sheets(1).

Sub ei()
Sheets(1).PrintPreview
x = Sheets(1).HPageBreaks.Count + 1
MsgBox x
End Sub

For the number of sheets in a workbook

Sub dk()
y = ActiveWorkbook.Sheets.Count
MsgBox y
End Sub






"speedy" wrote:

I am looking to create a simple macro. I have created some range names,
example is page1 all the way to page10. I want to copy these ranges to
another worksheet. The problem is my macro is only good if I know how many
range pages that I will actually need. I want to know how I can create a
loop that will work for 1 page or 100 pages.
--
Mr Speedy



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
Reference Range Names in Macro Karin Excel Discussion (Misc queries) 8 August 27th 09 02:32 PM
Macro and range names Brad Excel Programming 6 February 23rd 07 05:35 PM
Using range names in a macro formula melric Excel Programming 8 March 17th 06 07:48 PM
Macro for Range Names SamDev Excel Programming 11 November 23rd 05 03:25 AM


All times are GMT +1. The time now is 09:33 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"