referencing named ranges in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Well that's easy. Probably should have tried that one on my own.

Thanks.
 
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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top