I need to copy data from a workbook to another, but anytime i tried to run my macro a get the runtime error "438" on the line containing the "select" operation. Thanks to all , and sorry if i've made noob errors but i'm relatively new to vba :)
here's my code:
Private Sub FileChoose_Click()
Dim fd As FileDialog
Dim FileName As String
Dim wb1 As Workbook
Set wb1 = ActiveWorkbook
Dim wb2 As Workbook
Set fd = Application.FileDialog(msoFileDialogOpen)
Dim filechosen As Integer
filechosen = fd.Show
fd.Title = "Scegliere il file da confrontare"
fd.InitialView = msoFileDialogViewSmallIcons
fd.Filters.Clear
fd.Filters.Add "Excel File", "*.xlsx"
fd.Filters.Add "Excel File con Macro", "*.xlsm"
fd.FilterIndex = 1
fd.ButtonName = "Apri"
If filechosen <> -1 Then
MsgBox "Nessun File Selezionato"
Else
FileName = fd.SelectedItems(1)
Set wb2 = Workbooks.Open(FileName)
Call Insert(wb2, wb1)
End If
End Sub
Private Sub Insert(wb2 As Workbook, wb1 As Workbook)
Dim myrange As Range
Set myrange = Range("B2:GT22")
For i = 1 To 24
wb2.Worksheets(i).Activate
wb2.ActiveSheet.myrange.Select <--- there is the error
Selection.Copy
wb1.Worksheets(i + 1).Activate
wb1.ActiveSheet.myrange.Select
Selection.Paste
Next i
End Sub