I am new to VBA. I am trying to copy columns from one workbook to another workbook. Below is the sub I am trying to use but getting an error of "run time error 9 - subscript out of range". Any suggestions?
Sub copydata(wbSource As String, wsSource As String, rangeSource As String, wbDest As String, wsDest As String, rangeDest As String)
Workbooks(wbSource).Worksheets(wsSource).Range(rangeSource).copy Destination:=Workbooks(wbDest).Worksheets(wsDest).Range(rangeDest)
End Sub
Sub result()
' I also tried to set wsSource and wsDest to 1 but still doesn't work
Call copydata("es.csv", "es", "A:B", "Workbook1.xlsm", "result", "A:B")
End Sub
Thanks
EDIT: They are in the same directory. And I create the module in Workbook1.xlsm