Essentially my problem is that I have an already open workbook that I am running the VBA code from. I want to prompt the user to open a csv excel file, copy everything in the first sheet (I don't know what the sheet name is) and then paste everything from that sheet to a sheet in my Active Workbook. Right now the code will prompt the user and will allow them to select a csv but I get an error on the line:
Workbooks(FileToOpen).Activate
The error reads
"Subscript out of range"
Thanks for helping me on this.
Sub Popular()
FileToOpen = Application.GetOpenFilename _
(Title:="Please Choose the RTCM File", _
FileFilter:="Excel Files *.csv (*.csv),")
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Duh!!!" ' Notification that nothing
is chosen
Exit Sub
Else ' Load the file, copy the first sheet and paste it in active sheet ...
ThisWorkbook.Activate
ThisWorkbook.ActiveSheet.Range("A1:Z65536").ClearContents
Workbooks(FileToOpen).Activate
lrow = Workbooks(FileToOpen).Sheets("Sheet1").Cells(65536, 1).End(xlUp).Row
Workbooks(FileToOpen).Sheets("Sheet1").Range("A1:Z" & lrow).Copy
ThisWorkbook.Activate
ThisWorkbook.ActiveSheet.Range("A1").PasteSpecial xlPasteValues
End If
End Sub