Yes, your question is clear. To increment the cell reference by one row, you can use the
property in VBA. Here's how you can modify your code:
- Find the last row in the "Main Sheet" using the method.
Code:
Dim lastRow As Long
lastRow = Sheets("Main Sheet").Cells(Rows.Count, "A").End(xlUp).Row
- Copy the active sheet.
Code:
ActiveSheet.Copy After:=ActiveSheet
- Assign the formula to the "Special Cell1" using the property.
Code:
Range("E4").Formula = "='Main Sheet'!" & Range("E4").Offset(lastRow, 1).Address(False, False)
- Assign the formula to the "Special Cell2" using the property.
Code:
Range("F20").Formula = "='Main Sheet'!" & Range("F20").Offset(lastRow, 2).Address(False, False)
In this code, we first find the last row in the "Main Sheet" using the
method. Then we use the
property to increment the row reference by one. We concatenate the row number with the formula using the & symbol. Finally, we assign the formula to the cell using the
property.
Note that this code assumes that the "Main Sheet" is in the first column and that the "Special Cells" are in the second and third columns. If they are in different columns, you will need to modify the column reference in the formula accordingly.