notmeiquit
New Member
- Joined
- Jun 14, 2006
- Messages
- 13
My boss has a complex Excel file he works with. Has multiple sheets that need to equal the same value across multiple sheets. Sheet names are Q1, Q2, Q3, R1, R2, R3 and R4 (in that order).
Q1 is the starting sheet. If a change is made on a specific cells in Q1 the value will be the same in Q2, Q3 and so on all the way to R4. This is accomplished with the simple = Prior sheet
formula in the cells.
When working in the sheets, if changes are made, lets say in Q3 by replacing the = formula (in a cell) with a hard value that is ok, R1, R2 and so on will pick up on the change and carry it forward.
I am struggling with creating VBA code that will loop through the cells and replace the changed cells with the = formula to equal the prior sheets corresponding cell. (Resetting every sheet for the next time it is used). Most of the cells are not next to another cell (like a range) so making an array with plugged cells to change is the only way.
MY ultimate goal would be to have the Array value, The actual cell location (i have in the array), [see array below] used as a variable in the range().select. This will keep the code to a minimum. My web searching has giving me no answers. I am close but I get run time error 1004 Method 'Range' of object'_Global' Failed
In the code below I only put a few cell locations that need to be updated. I will have about 30 or 40 cells to update. Any help would be greatly appreciated.
Thanks for your time.
Q1 is the starting sheet. If a change is made on a specific cells in Q1 the value will be the same in Q2, Q3 and so on all the way to R4. This is accomplished with the simple = Prior sheet
formula in the cells.
When working in the sheets, if changes are made, lets say in Q3 by replacing the = formula (in a cell) with a hard value that is ok, R1, R2 and so on will pick up on the change and carry it forward.
I am struggling with creating VBA code that will loop through the cells and replace the changed cells with the = formula to equal the prior sheets corresponding cell. (Resetting every sheet for the next time it is used). Most of the cells are not next to another cell (like a range) so making an array with plugged cells to change is the only way.
MY ultimate goal would be to have the Array value, The actual cell location (i have in the array), [see array below] used as a variable in the range().select. This will keep the code to a minimum. My web searching has giving me no answers. I am close but I get run time error 1004 Method 'Range' of object'_Global' Failed
In the code below I only put a few cell locations that need to be updated. I will have about 30 or 40 cells to update. Any help would be greatly appreciated.
Thanks for your time.
VBA Code:
Sub RepairSheets()
Dim indexArr As Variant
Dim i As Long
indexArr = Array("B3", "D3", "J3", "N3")
For i = LBound(indexArr) To UBound(indexArr)
Sheets("R4").Select: Range(indexArr).Select: ActiveCell.FormulaR1C1 = "='R3'!RC"
Sheets("R3").Select: Range(indexArr).Select: ActiveCell.FormulaR1C1 = "='R2'!RC"
Sheets("R2").Select: Range(indexArr).Select: ActiveCell.FormulaR1C1 = "='R1'!RC"
Sheets("R1").Select: Range(indexArr).Select: ActiveCell.FormulaR1C1 = "='Q3'!RC"
Sheets("Q3").Select: Range(indexArr).Select: ActiveCell.FormulaR1C1 = "='Q2'!RC"
Sheets("Q2").Select: Range(indexArr).Select: ActiveCell.FormulaR1C1 = "='Q1'!RC"
Next i
End Sub