I have tried to solve this seemingly easy problem, but can't find a solution. I'm trying to copy a selected cell, plus 2 cells that follow, then create a new row and paste the contents in the first cell of the new row.
The first part works fine, After selection the prompt asks if this is the correct cell to copy, then the copy happens, and a new row is created with the first cell selected, but the code fails on the PasteSpecial.
You will see comments of what I tried, in the code, that have not worked.
I'd appreciate any help that is given. Thanks in advance. Dave
Sub SelectCell_on_RowThenAdd2andAskYorN_AddRow_Paste()
Dim Msg, Style, Response, MyString
Msg = "Is Job Number the job you wish to copy?"
Style = vbYesNo
Response = MsgBox(Msg, Style)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
ActiveCell.Select 'Takes active cell and offsets 1 to the right
Selection.Resize(Selection.Rows.Count, _
Selection.Columns.Count + 2).Select ' Resizes selection by 2 rows
Selection.Copy
Else ' User chose No.
MyString = "No" ' Perform some action.
MsgBox "Choose the correct Job Number," & (Chr(13)) & "then Click the Copy Button.", vbOKOnly
End If
Dim oNewRow As ListRow
Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)
oNewRow.Range.Cells(1, 1).Select
'Cells(Selection.Row, 1).Select --- Did not work
'ActiveSheet.Paste --- Did not work
'Paste Special gives error PasteSpecial Method of Range Class Failed
Selection.PasteSpecial Paste:=xlValues
End Sub