Saltysteve
New Member
- Joined
- Jul 23, 2014
- Messages
- 36
- Office Version
- 365
- Platform
- Windows
Hi all,
I am trying to get a macro to insert a row at a selected position then pause and allow me to select two consecutive cells from another location which the macro then copies and pastes the values into columns D and E of the newly inserted row.
I sort of have some code that semi works except it only copies and pastes the first cell.
Any assistance will be appreciated.
Sub InsertRow()
'Declare variables
Dim Rng As Range
ScreenUpdating = False
'Insert row
Selection.Resize(rowsize:=2).Rows(2).EntireRow.Resize(rowsize:=1).Insert Shift:=xlDown
On Error Resume Next
Set Rng = Application.InputBox("Select the 2 cells to be copied", Type:=8) ' This only copies the first cell, even though 2 cells are selected
SO = Rng(1).Value 'Selection.Copy does copy both cells but not sure how to get it into the inserted row
ActiveCell.Offset(1, 0).Value = SO ' the active cell is the one above the inserted row in column D. I need to move down 1, select the cells in D and E and paste the data
ScreenUpdating = True
End Sub
I am trying to get a macro to insert a row at a selected position then pause and allow me to select two consecutive cells from another location which the macro then copies and pastes the values into columns D and E of the newly inserted row.
I sort of have some code that semi works except it only copies and pastes the first cell.
Any assistance will be appreciated.
Sub InsertRow()
'Declare variables
Dim Rng As Range
ScreenUpdating = False
'Insert row
Selection.Resize(rowsize:=2).Rows(2).EntireRow.Resize(rowsize:=1).Insert Shift:=xlDown
On Error Resume Next
Set Rng = Application.InputBox("Select the 2 cells to be copied", Type:=8) ' This only copies the first cell, even though 2 cells are selected
SO = Rng(1).Value 'Selection.Copy does copy both cells but not sure how to get it into the inserted row
ActiveCell.Offset(1, 0).Value = SO ' the active cell is the one above the inserted row in column D. I need to move down 1, select the cells in D and E and paste the data
ScreenUpdating = True
End Sub