Using Excel 2013.
When I try to call my sub CopyPasteData, I get the error ""vba byref argument type mismatch". The problem most likely is due to the passthrough value for tofile.
Can someone help, please? Thank you!
Sub Main ()
Dim ThisPeriod as string
Dim WBS As Workbook
ThisPeriod = Range("B3").Text
Set WB3 = Workbooks("Tables_" & ThisPeriod & ".xls")
Call CopyPasteData("B5:S23", WB3, "id", "B11:S29")
End Sub
Sub CopyPasteData (fromsht As String, fromrange As String, tofile As workbook, tosht As String, torange As String)
ThisWorkbook.Sheets(fromsht).Range(fromrange).Copy
tofile.Sheets(tosht).Range(torange).PasteSpecial Paste:=xlPasteValues
End Sub
When I try to call my sub CopyPasteData, I get the error ""vba byref argument type mismatch". The problem most likely is due to the passthrough value for tofile.
Can someone help, please? Thank you!
Sub Main ()
Dim ThisPeriod as string
Dim WBS As Workbook
ThisPeriod = Range("B3").Text
Set WB3 = Workbooks("Tables_" & ThisPeriod & ".xls")
Call CopyPasteData("B5:S23", WB3, "id", "B11:S29")
End Sub
Sub CopyPasteData (fromsht As String, fromrange As String, tofile As workbook, tosht As String, torange As String)
ThisWorkbook.Sheets(fromsht).Range(fromrange).Copy
tofile.Sheets(tosht).Range(torange).PasteSpecial Paste:=xlPasteValues
End Sub