PDA

View Full Version : Locking Formulas



zoom38
04-26-2006, 09:50 PM
Anyone know of a way to lock formulas in vba? My problem is that I have a macro that copies a row and then pastes it in the next row. This row has references a row about 30 rows down and I want these refernces changed by 1 which it does. It works and the cell references are correct. Next the macro copies a row that is down further and pastes that in the next row. Here is where the problem occurs. Now in the first row that was copied a cell reference is changed because it references the row that is copied the second time. Basically Im looking to copy and paste a row and then lock those formulas from changing.


Rows("34:34").Select
Selection.Copy
Rows("35:35").Select
Selection.Insert shift:=xlDown

Rows("65:65").Select
Selection.Copy
Rows("66:66").Select
Selection.Insert shift:=xlDown

Rows("96:96").Select
Selection.Copy
Rows("97:97").Select
Selection.Insert shift:=xlDown

Rows("127:127").Select
Selection.Copy
Rows("128:128").Select
Selection.Insert shift:=xlDown
Range("A1").Select



Thanks
Gary

Jacob Hilderbrand
04-26-2006, 10:14 PM
If you want to lock the formula, you can use absolute references. Just put a $ in front of the column and/or row in the formula and those will be frozen.

i.e.

A1
$A1
A$1
$A$1

zoom38
04-26-2006, 10:32 PM
I do understand the absolute references but I need the cell references to change on the copy and paste but after the paste I want the formulas or cell references locked.