happyhungarian
Board Regular
- Joined
- Jul 19, 2011
- Messages
- 242
- Office Version
- 365
- Platform
- Windows
Hi, I'm using the following code to auto insert rows and data labels in Column D for me. Can this be altered to insert a simple formula? Basically what I would like is to keep the code for column D as is {entering Customer1, Customer2, and Cusomer3} but in columns A through C I'd also like it to enter a formula that simply references the cell directly above. Example. My headers are in Row 1, the VBA skips row 2 and auto-inserts 3 rows and places "Customer1" in cell D3, "Customer2" in cell D4, "Customer3" in cell D5. Now what i want to add is in cell A3 i want it to reference A2, cell B3 to reference B2, cell C3 to reference C2. Then the same for row 4, A4 reference A3, B4 reference B3 etc. I hope I made sense!
Dim lr As Long, fr As Long, i As Long
Dim MyCol As String, MyVals As Variant
MyCol = "D" 'Adjust to the appropriate column containing the list
MyVals = Array("Customer1", "Customer2", "Customer3")
lr = Cells(Rows.Count, MyCol).End(xlUp).Row + 1
fr = Columns(MyCol).Find("CCC").Row + 2 'Adjust the name of the header
For i = lr To fr Step -1
Rows(i).Resize(3).EntireRow.Insert
Cells(i, MyCol).Resize(3, 1).Value = Application.Transpose(MyVals)
Dim lr As Long, fr As Long, i As Long
Dim MyCol As String, MyVals As Variant
MyCol = "D" 'Adjust to the appropriate column containing the list
MyVals = Array("Customer1", "Customer2", "Customer3")
lr = Cells(Rows.Count, MyCol).End(xlUp).Row + 1
fr = Columns(MyCol).Find("CCC").Row + 2 'Adjust the name of the header
For i = lr To fr Step -1
Rows(i).Resize(3).EntireRow.Insert
Cells(i, MyCol).Resize(3, 1).Value = Application.Transpose(MyVals)
Last edited: