Jul 10 2023 04:00 AM
I am a bit of a beginner to excel and have an issue. I need to insert a fixed amount of cells in between every cell of 9 separate, very long columns. I don't want to manually insert 13 cells in between around 45000 cells as that would take far to long.
Jul 10 2023 04:20 AM
Inserting 13 blank rows below each row won't work?
Jul 10 2023 04:22 AM
Jul 10 2023 04:27 AM
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert > Module.
Copy the following code into the module:
Sub InsertCells()
Dim c As Variant
Dim r As Long
Dim m As Long
Application.ScreenUpdating = False
' Change the columns as needed
For Each c In Array("B", "D", "G", "H", "K", "N", "Z", "AD", "AG")
m = Range(c & Rows.Count).End(xlUp).Row
For r = m To 2 Step -1
Range(c & r).Resize(13).Insert Shift:=xlShiftDown
Next r
Next c
Application.ScreenUpdating = True
End Sub
Change the columns to the one you want.
With the insertion point anywhere in the code, press F5 to run it. It will take some time.
Switch back to Excel
Jul 10 2023 06:36 AM
@Hans Vogelaar I have been given a message saying "run-time error '1004': insert method of Range class failed" as there is a bug on line 10. Do you know what is wrong ?
Jul 10 2023 08:12 AM
The code works when I try it. Could you attach a small sample workbook demonstrating the problem (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar?
Jul 11 2023 04:51 AM
SolutionJul 11 2023 04:51 AM
Solution