I have the below VBA which:
1. Makes a copy of an existing sheet
2. Inserts extra columns
3. Adds column headers
4. Adds a formula to the new columns in row 2
5. Auto-fills the formula down to the last row (based on column A)
6. Repeats the above for a number of other columns.
It works, however takes quite a long time. My data set has thousands of row and 10 new columns to add and fill with formulas.
Is there a more efficient way to do this?
1. Makes a copy of an existing sheet
2. Inserts extra columns
3. Adds column headers
4. Adds a formula to the new columns in row 2
5. Auto-fills the formula down to the last row (based on column A)
6. Repeats the above for a number of other columns.
It works, however takes quite a long time. My data set has thousands of row and 10 new columns to add and fill with formulas.
Is there a more efficient way to do this?
VBA Code:
Sheets("Sheet1").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = "Sheet2"
lastRow = Range("A" & Rows.Count).End(xlUp).Row
Columns("F:G").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("F1").Value = "Header 1"
Range("G1").Value = "Header2"
Range("F2").FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet3!C[-1],1,FALSE)"
Range("F2").AutoFill Destination:=Range("F2:F" & lastRow)
Range("G2").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-2],Sheet4!C[-2],1,FALSE),""N/A"")"
Range("G2").AutoFill Destination:=Range("G2:G" & lastRow)
'Repeat to add X more new columns and formulas