Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default referencing named ranges in VBA

I have the following macro, which hides and unhides some rows:

Sub ShowMWDC()
' Freezes window at cell A41
' Unhides rows 41:83
' Hides rows 2:39
Cells.Select
Range("B1").Activate
Selection.EntireRow.Hidden = False
Selection.EntireColumn.Hidden = False
Rows("41:83").Select
Selection.EntireRow.Hidden = False
Rows("2:40").Select
Selection.EntireRow.Hidden = True
Range("A44").Select
ActiveWindow.FreezePanes = False
ActiveWindow.FreezePanes = True
End Sub


Rows 41:83 correspond to a named range, "MWDC" and rows 2:40 correspond to a
named range, "Migration". How would I modify the above to use these named
ranges as opposed to the rows?

Thanks,

Dave
--
Brevity is the soul of wit.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default referencing named ranges in VBA

Hi, Dave-
Try this one:
Range(Names("MWDC").RefersTo).Select

Dave O

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default referencing named ranges in VBA

Just replace
Rows("41:83").Select
with
Range("MWDC").Select


etc.



--
Gary's Student
gsnu200702


"Dave F" wrote:

I have the following macro, which hides and unhides some rows:

Sub ShowMWDC()
' Freezes window at cell A41
' Unhides rows 41:83
' Hides rows 2:39
Cells.Select
Range("B1").Activate
Selection.EntireRow.Hidden = False
Selection.EntireColumn.Hidden = False
Rows("41:83").Select
Selection.EntireRow.Hidden = False
Rows("2:40").Select
Selection.EntireRow.Hidden = True
Range("A44").Select
ActiveWindow.FreezePanes = False
ActiveWindow.FreezePanes = True
End Sub


Rows 41:83 correspond to a named range, "MWDC" and rows 2:40 correspond to a
named range, "Migration". How would I modify the above to use these named
ranges as opposed to the rows?

Thanks,

Dave
--
Brevity is the soul of wit.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default referencing named ranges in VBA

Gary's kung fu is better: I'm going to change my code archive.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default referencing named ranges in VBA

Well that's easy. Probably should have tried that one on my own.

Thanks.
--
Brevity is the soul of wit.


"Gary''s Student" wrote:

Just replace
Rows("41:83").Select
with
Range("MWDC").Select


etc.



--
Gary's Student
gsnu200702


"Dave F" wrote:

I have the following macro, which hides and unhides some rows:

Sub ShowMWDC()
' Freezes window at cell A41
' Unhides rows 41:83
' Hides rows 2:39
Cells.Select
Range("B1").Activate
Selection.EntireRow.Hidden = False
Selection.EntireColumn.Hidden = False
Rows("41:83").Select
Selection.EntireRow.Hidden = False
Rows("2:40").Select
Selection.EntireRow.Hidden = True
Range("A44").Select
ActiveWindow.FreezePanes = False
ActiveWindow.FreezePanes = True
End Sub


Rows 41:83 correspond to a named range, "MWDC" and rows 2:40 correspond to a
named range, "Migration". How would I modify the above to use these named
ranges as opposed to the rows?

Thanks,

Dave
--
Brevity is the soul of wit.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default referencing named ranges in VBA

The key point is that the name of a named range is just a string, not a
variable. A very common mistake is to use
Range(MWDC)
instead of
Range("MWDC")
--
Gary's Student
gsnu200702


"Dave F" wrote:

Well that's easy. Probably should have tried that one on my own.

Thanks.
--
Brevity is the soul of wit.


"Gary''s Student" wrote:

Just replace
Rows("41:83").Select
with
Range("MWDC").Select


etc.



--
Gary's Student
gsnu200702


"Dave F" wrote:

I have the following macro, which hides and unhides some rows:

Sub ShowMWDC()
' Freezes window at cell A41
' Unhides rows 41:83
' Hides rows 2:39
Cells.Select
Range("B1").Activate
Selection.EntireRow.Hidden = False
Selection.EntireColumn.Hidden = False
Rows("41:83").Select
Selection.EntireRow.Hidden = False
Rows("2:40").Select
Selection.EntireRow.Hidden = True
Range("A44").Select
ActiveWindow.FreezePanes = False
ActiveWindow.FreezePanes = True
End Sub


Rows 41:83 correspond to a named range, "MWDC" and rows 2:40 correspond to a
named range, "Migration". How would I modify the above to use these named
ranges as opposed to the rows?

Thanks,

Dave
--
Brevity is the soul of wit.

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
Using Query and expanding named ranges [email protected] Excel Discussion (Misc queries) 1 July 21st 06 08:35 PM
Importing Excel named ranges using MS Query KHanna Excel Discussion (Misc queries) 0 July 21st 06 04:49 AM
INDIRECT and Named Ranges referencing closed workbook gpie Excel Worksheet Functions 9 October 6th 05 11:24 PM
Excel will not include all of my non-adj ranges in a named range?? Renlimanit Excel Worksheet Functions 3 September 22nd 05 02:34 PM
Named dynamic ranges, copied worksheets and graph source data WP Charts and Charting in Excel 1 November 28th 04 05:19 PM


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