Forum Discussion
How to edit cells
- Feb 27, 2023
Save the workbook before you do the following.
If you don't like the result, you can close the workbook without saving it.
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert > Module (or press Alt+I, M) to create a new code module.
Copy the code listed below into the code window.
With the insertion point anywhere in the code, press F5 to run it.
Switch back to Excel to inspect the result.
If you won't need the macro anymore, save and close the workbook. Excel will display a warning that macros will be lost. Click Yes to save the workbook anyway.
If you'd like to keep the macro, save the workbook as a macro-enabled workbook (*.xlsm).
You will have to allow macros when you open it.
The code:
Sub InsertRows() Dim r As Long Dim m As Long Application.ScreenUpdating = False m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row For r = m To 2 Step -1 Range("A" & r).EntireRow.Insert Next r Application.ScreenUpdating = True End Sub
Save the workbook before you do the following.
If you don't like the result, you can close the workbook without saving it.
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert > Module (or press Alt+I, M) to create a new code module.
Copy the code listed below into the code window.
With the insertion point anywhere in the code, press F5 to run it.
Switch back to Excel to inspect the result.
If you won't need the macro anymore, save and close the workbook. Excel will display a warning that macros will be lost. Click Yes to save the workbook anyway.
If you'd like to keep the macro, save the workbook as a macro-enabled workbook (*.xlsm).
You will have to allow macros when you open it.
The code:
Sub InsertRows()
Dim r As Long
Dim m As Long
Application.ScreenUpdating = False
m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For r = m To 2 Step -1
Range("A" & r).EntireRow.Insert
Next r
Application.ScreenUpdating = True
End Sub