I am trying to write code to insert two empty rows after a data line, then skip one data line, then insert two empty rows, then skip, etc. This is for a 3-column table that can vary in length. The purpose is to allow the data to be pasted into an Excel file that is both password protected and which contain merged cells (so I cannot unprotect it or un-merge any cells). I have been modifying variations of the following, which inserts one row, not two:
Sub Insert()
Dim i As Long, s, e
s = InputBox("Starting Row")
e = InputBox("Ending Row" & Chr(10) & Chr(10) & _
"(Must be equal or greater than Starting Row)")
Application.ScreenUpdating = False
If (s = "") + (e = "") + (s > e) Then Exit Sub
If (IsNumeric(s) = False) + (IsNumeric(e) = False) Then Exit Sub
For i = s To e * 2 - s Step 2
Rows(i).insert
Next
Application.ScreenUpdating = True
End Sub
This code has a nice feature in that it prompts for the entry of a starting and ending row, and requires that one only place the cursor in the starting row, but as it inserts only one row, it won't serve the purpose. Variations have not produced the desired result. I don't know Excel VBA well enough to figure it out on my own...
Sub Insert()
Dim i As Long, s, e
s = InputBox("Starting Row")
e = InputBox("Ending Row" & Chr(10) & Chr(10) & _
"(Must be equal or greater than Starting Row)")
Application.ScreenUpdating = False
If (s = "") + (e = "") + (s > e) Then Exit Sub
If (IsNumeric(s) = False) + (IsNumeric(e) = False) Then Exit Sub
For i = s To e * 2 - s Step 2
Rows(i).insert
Next
Application.ScreenUpdating = True
End Sub
This code has a nice feature in that it prompts for the entry of a starting and ending row, and requires that one only place the cursor in the starting row, but as it inserts only one row, it won't serve the purpose. Variations have not produced the desired result. I don't know Excel VBA well enough to figure it out on my own...