I am trying to make sheet 1 a place to enter data and sheet 2 into a publishable sheet. All my code works until I try and insert the range I copied from sheet 1. I tested it and range is selected if I don't enter the, Selection.Insert Shift:=xlDown command. Once I put this part of visual basics into the macro the copied range selected, deselects, and the insert command doesn't work.
Here is my code:
Option Explicit
Sub CopyandInsert()
' CTR+a is the shortcut key
ThisWorkbook.Worksheets("Sheet2").Range("A1:D400").ClearContents
Dim wsData As Worksheet
Set wsData = ThisWorkbook.Worksheets("Sheet1")
Dim wsPublishSheet As Worksheet
Set wsPublishSheet = ThisWorkbook.Worksheets("Sheet2")
wsData.Select
With wsData
On Error Resume Next
'//clear out filter
.ShowAllData
Range("A1:D1").AutoFilter 3, "LC"
End With ' LC Filter Complete
With wsData.AutoFilter.Range
.Offset(1, 0).Resize(.Rows.Count - 1).Copy
End With 'takes header out of the range I want to copy
wsPublishSheet.Select
Range("A12:D12").Select
Selection.Insert Shift:=xlDown ' Inserts copied cells into the range (this command doesn't work)
'Selection.Insert Shift:=xlDown 'If I want to paste, delete the Selection.Insert
'method and replace it with, ActiveSheet.paste
End Sub
Here is my code:
Option Explicit
Sub CopyandInsert()
' CTR+a is the shortcut key
ThisWorkbook.Worksheets("Sheet2").Range("A1:D400").ClearContents
Dim wsData As Worksheet
Set wsData = ThisWorkbook.Worksheets("Sheet1")
Dim wsPublishSheet As Worksheet
Set wsPublishSheet = ThisWorkbook.Worksheets("Sheet2")
wsData.Select
With wsData
On Error Resume Next
'//clear out filter
.ShowAllData
Range("A1:D1").AutoFilter 3, "LC"
End With ' LC Filter Complete
With wsData.AutoFilter.Range
.Offset(1, 0).Resize(.Rows.Count - 1).Copy
End With 'takes header out of the range I want to copy
wsPublishSheet.Select
Range("A12:D12").Select
Selection.Insert Shift:=xlDown ' Inserts copied cells into the range (this command doesn't work)
'Selection.Insert Shift:=xlDown 'If I want to paste, delete the Selection.Insert
'method and replace it with, ActiveSheet.paste
End Sub