Hi,
I have a formula that I need to copy from a certain cell ("Cell A") to the cell immediately to the right on the same row ("Cell "B").
These cells change each week as I roll forward a cash flow forecast. So for the 2nd week Cell B becomes Cell A and needs to be copied directly to the right again.
I want to select the appropriate Cell A each week based on a static row but the moving column. The columns represent the week of the year for the cash flow.
The date I want to lookup against is the current week, always present in cell H19 of the worksheet. For example, Cell H19 might contain the value "9/5/2020"
The dates I want to match against are in row 27. With 9/5/2020 being in cell AQ27.
In my code I set the active cell as F20 to start with as a base. The number of columns to the right are mapped out on row 20 of the worksheet (grouped rows, not shown on output). For example, cell AQ20 contains the hardcoded value "38". Being 38 columns from column F.
My code is below (with row 81 being the correct row, shown as 61 in row offset):
ActiveCell.Offset(61, (Application.WorksheetFunction.Index(Range("R20:DH20"), WorksheetFunction.Match(Cells(H19).Value, Range("R27:DH27"), 0)))).Range("A1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:B1"), Type:= _
xlFillDefault
I am receiving run time error 1004: Application-defined or object defined error
Any assistance would be hugely appreciated!
Thanks,
Jeff
I have a formula that I need to copy from a certain cell ("Cell A") to the cell immediately to the right on the same row ("Cell "B").
These cells change each week as I roll forward a cash flow forecast. So for the 2nd week Cell B becomes Cell A and needs to be copied directly to the right again.
I want to select the appropriate Cell A each week based on a static row but the moving column. The columns represent the week of the year for the cash flow.
The date I want to lookup against is the current week, always present in cell H19 of the worksheet. For example, Cell H19 might contain the value "9/5/2020"
The dates I want to match against are in row 27. With 9/5/2020 being in cell AQ27.
In my code I set the active cell as F20 to start with as a base. The number of columns to the right are mapped out on row 20 of the worksheet (grouped rows, not shown on output). For example, cell AQ20 contains the hardcoded value "38". Being 38 columns from column F.
My code is below (with row 81 being the correct row, shown as 61 in row offset):
ActiveCell.Offset(61, (Application.WorksheetFunction.Index(Range("R20:DH20"), WorksheetFunction.Match(Cells(H19).Value, Range("R27:DH27"), 0)))).Range("A1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:B1"), Type:= _
xlFillDefault
I am receiving run time error 1004: Application-defined or object defined error
Any assistance would be hugely appreciated!
Thanks,
Jeff