Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Macro Reference Cells

Problem: When I write a macro that acts on certain cells, the macro fails to
act properly if I insert rows above those cells that are normally acted upon.

I've tried to use both relative and absolute references, but when the row is
inserted the original cell reference in Visual Basic is not changed, but
remains the same.

Question: Is there a way to write a macro so that when row or column is
inserted the macro can go from any cell and find the correct cells to operate
for the macro?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro Reference Cells

The short answer is no - there is no automatic adjustment of addresses used
in code.

That said, most work around the column by analyzing the structure of the
worksheet to identify the area they need to work. This would mean looking
for unique attributes and values associated with the cells. Another
approach is to use a defined name (insert =Name=Define) with refers to the
upper left corner of the range (as an example). This would be adjusted by
excel as rows are inserted and VBA could rely on that.

--
Regards,
Tom Ogilvy


"bmorganh" wrote:

Problem: When I write a macro that acts on certain cells, the macro fails to
act properly if I insert rows above those cells that are normally acted upon.

I've tried to use both relative and absolute references, but when the row is
inserted the original cell reference in Visual Basic is not changed, but
remains the same.

Question: Is there a way to write a macro so that when row or column is
inserted the macro can go from any cell and find the correct cells to operate
for the macro?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro Reference Cells

Use named ranges instead. For example say cell A7 is called _A7 and contains
a vlaue of XXXXX and you insert a row above if you refer to the named range
it will now be A8 that now contains XXXXX.

Mike

"bmorganh" wrote:

Problem: When I write a macro that acts on certain cells, the macro fails to
act properly if I insert rows above those cells that are normally acted upon.

I've tried to use both relative and absolute references, but when the row is
inserted the original cell reference in Visual Basic is not changed, but
remains the same.

Question: Is there a way to write a macro so that when row or column is
inserted the macro can go from any cell and find the correct cells to operate
for the macro?

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
Formulas that reference cells that reference another cell Andrea Excel Discussion (Misc queries) 7 October 19th 06 08:14 AM
reference format Range(Cells(),Cells()) Stefi Excel Programming 5 December 16th 05 02:25 PM
Macro to Reference Column Next to Current Reference dolphinv4 Excel Discussion (Misc queries) 2 April 11th 05 08:36 AM
How do I reference the last 3 cells in a row as cells are added Still Learning Excel Worksheet Functions 6 January 8th 05 05:10 PM
How To: Macro Command To Reference Populated Cells Only TJM[_2_] Excel Programming 2 August 6th 04 10:51 PM


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