PDA

Click to See Complete Forum and Search --> : Updating cell references in Excel macros [Self-resolved]


krtxmrtz
Jun 12th, 2006, 05:32 PM
Assume you have a cell in Excel with the formula "=D8*C6". If you now insert a row above of a column at the left of the referred cells D8 and C6, the references are automatically updated.
But if you have this line within a macro:

Sheets("MU").Cells(30, 6).Value = "100"

and you add a row on top of cell (30,6), the macro is of course not updated but now the correct line should read

Sheets("MU").Cells(31, 6).Value = "100"

So, now, I find myself in an uncomfortable position: I have lots of such references in various macros and need to insert one or two rows to make room for a checkbox that wouldn't look too nice if placed somewhere else. What could I do to avoid extra work?

krtxmrtz
Jun 13th, 2006, 04:29 AM
I apologize for I've just realized I had made a mistake when I stated my question.

The correct question was, what can you do whan you add a row above a cell referred to in another cell's formula:

Instead of:

Sheets("MU").Cells(30, 6).Value = "100"

I should have written something like:

Sheets("MU").Cells(30, 6).Value = Sheets("MU").Cells(26, 18).Value

so that when you add a row above row 26 the macro assigns to cell (30,6) the value of cell (26,18) the contents of which has been now pushed to cell (27,18).

All right, don't you guys rack your brains, I came up with the solution already. Just define a variable pointing to the relevant cell.

Can I rate myself up? :D