I have a macro to copy data based on filters. But some cells that are being copied from already have formulas in them, so I want to copy that and paste only as text or values.I tried using the below. I tried xlValues and Format text, both of them giving errors - Run Time error '438' . Object doesn't support this property or method.
Sub DS()
Dim sourceWorkbook As Workbook
Dim targetWorkbook As Workbook
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim sourceWorkbookPath As String
Dim targetWorkbookPath As String
Dim lastRow As Long
' Define workbooks paths
sourceWorkbookPath = "Exceptional Transfer -2020 v2.xlsm"
targetWorkbookPath = "template2.xlsx"
' Set a reference to the target Workbook and sheets
Set sourceWorkbook = Workbooks.Open(sourceWorkbookPath)
Set targetWorkbook = Workbooks.Open(targetWorkbookPath)
' definr worksheet's names for each workbook
Set sourceSheet = sourceWorkbook.Worksheets("A")
Set targetSheet = targetWorkbook.Worksheets("B")
With sourceSheet
' Get last row
lastRow = .Range("K" & .Rows.Count).End(xlUp).Row
.Range("A1:Q1").AutoFilter Field:=14, Criteria1:="PENDING"
.Range("A1:Q1").AutoFilter Field:=11, Criteria1:="U3R", Operator:=xlOr, Criteria2:="U2R"
.Range("K2:K" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("A1")
.Range("C2:C" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("B1")
.Range("E2:E" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("E1").PasteSpecial xlValues
.Range("G2:G" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("F1")
.Range("S2:S" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("I1")
.Range("T2:T" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("J1")
.Range("U2:U" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=targetSheet.Range("C1")
End With
On Error Resume Next
sourceSheet.ShowAllData
On Error GoTo 0
End Sub