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 cell references in macros

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


--
Brevity is the soul of wit.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default cell references in macros

If you use Named Ranges rather than absolute row/column references, then the
macro will adapt (because the Named Ranges will also adapt)
--
Gary's Student


"Dave F" wrote:

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


--
Brevity is the soul of wit.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default cell references in macros

Perfect, thanks.

Dave
--
Brevity is the soul of wit.


"Gary''s Student" wrote:

If you use Named Ranges rather than absolute row/column references, then the
macro will adapt (because the Named Ranges will also adapt)
--
Gary's Student


"Dave F" wrote:

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


--
Brevity is the soul of wit.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default cell references in macros

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


"Dave F" wrote:

Perfect, thanks.

Dave
--
Brevity is the soul of wit.


"Gary''s Student" wrote:

If you use Named Ranges rather than absolute row/column references, then the
macro will adapt (because the Named Ranges will also adapt)
--
Gary's Student


"Dave F" wrote:

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


--
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
Auto-increment data source cell references when copying charts Dave Excel Discussion (Misc queries) 2 July 5th 06 07:45 PM
Converting to Absolute Cell References - en bloc Basher Bates Excel Worksheet Functions 7 May 11th 06 10:00 PM
Furmula Dependent Cell References ned Excel Discussion (Misc queries) 2 May 4th 06 05:03 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
Syntax for inferred cell references donesquire Excel Worksheet Functions 4 April 4th 05 09:29 PM


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