cell references in macros

G

Guest

I have the following macro:

Sub TCAPSfcst()
' Hides rows 85:120
' Hides columns AM:CP
' Freezes window at J4
Cells.Select
Range("B1").Activate
Selection.EntireRow.Hidden = False
Selection.EntireColumn.Hidden = False
Rows("85:120").Select
Selection.EntireRow.Hidden = True
Columns("AM:CP").Select
Selection.EntireColumn.Hidden = True
Range("J4").Select
ActiveWindow.FreezePanes = False
ActiveWindow.FreezePanes = True
End Sub

If I add or delete a column or row to this spreadsheet, the macro above
doesn't update its references. I now need to hide rows 85:120, hide columns
AM:CN, and freeze the window at cell H4.

This is easy enough to do manually by going into this code, and changing the
cell references accordingly. However, I am wondering if there is a way for
XL to dynamically update the code as rows and/or columns are added or deleted?

Thanks,

Dave
 
G

Guest

If you use Named Ranges rather than absolute row/column references, then the
macro will adapt (because the Named Ranges will also adapt)
 
G

Guest

You are very welcome. By the way, it is a good way to mark the end of
UsedRange in a set of worksheets.
 

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

Top