Hi Guys,
I need your help, on VBA code below. My aim is to be able to copy a range from one workbook to another and I get the Run Time Error 438 on the line colored red.
Can this code be corrected or is there an easier way to get this done?
Thanks.
Sub CopytoAnotherWorkbook()
Dim wbTarget As Workbook 'workbook where the data is to be pasted
Dim wbThis As Workbook 'workbook from where the data is to copied
Dim strName As String 'name of the source sheet/ target workbook
Set wbThis = ActiveWorkbook
strName = ActiveSheet.name
Set wbTarget = Workbooks.Open("C:\Users\asdf\Desktop\" & strName & ".xlsx")
wbTarget.Activate
wbTarget.Range("A1").Select
wbTarget.Range("A1:C10").ClearContents
wbThis.Activate
Application.CutCopyMode = False
wbThis.Range("A1:C10").Copy
wbTarget.Range("A1").PasteSpecial
Application.CutCopyMode = False
wbTarget.Save
wbTarget.Close
wbThis.Activate
Set wbTarget = Nothing
Set wbThis = Nothing
End Sub
Bookmarks