So I am reasonably new to VBA and am having trouble with this error. I am trying to set up a macro button that will allow me to import a sheet of data from two separate files whos location is specified in the main workbook.
The main workbook has the following tabs: Version, Start, Summary, Summary_BEL, Current Q, Previous Q, Mapping.
The worksheets to be copied have the same name as the workbooks they are located in.
Here is what I have so far:
The main workbook has the following tabs: Version, Start, Summary, Summary_BEL, Current Q, Previous Q, Mapping.
The worksheets to be copied have the same name as the workbooks they are located in.
Here is what I have so far:
Code:
Public Main_wb As Workbook
Public SheetName As String
Public Variable As String
Private Sub CommandButton1_Click()
Dim i As Integer
Dim folderCurrent As String
Dim FileCurrent As String
Dim FolderPrevious As String
Dim FilePrevious As String
Dim Tab_name As String
Dim Destination As String
Dim Variable As String
Dim column As Integer
Set Main_wb = ThisWorkbook
Main_wb.Worksheets("Start").Activate
Main_wb.Worksheets("Start").Calculate
folderCurrent = Worksheets("Start").Range("C12").Value
FolderPrevious = Worksheets("Start").Range("C13").Value
FileCurrent = Worksheets("Start").Range("D12").Value
FilePrevious = Worksheets("Start").Range("D13").Value
Call GetInputsBEN(folderCurrent, FolderPrevious, FileCurrent, FilePrevious, Tab_name)
End Sub
Public Function GetInputsBEN(folderCurrent As String, FileCurrent As String, FolderPrevious As String, FilePrevious As String, Tab_name As String)
Dim myFile As String
Dim SaveFile() As String
Dim paramSplit() As String
Dim d As Variant
Dim Row As Single
Dim k As Single
Dim paramRows As Single
Dim numLines As Long
Dim NameFile As String
Dim line As Variant
Dim Worksheet As String
Application.ScreenUpdating = False
Set Main_wb = ThisWorkbook
Main_wb.Worksheets(Tab_name).Activate
line = Cells(Rows.Count, "B").End(xlUp).Row
Main_wb.Worksheets(Tab_name).Range("A1:X" & line).ClearContents
myFile1 = folderCurrent & FileCurrent
Worksheet1 = folderCurrent & FileCurrent
myFile2 = FolderPrevious & FilePrevious
Worksheet2 = FolderPrevious & FilePrevious
Open myFile1 For Input As #6
Worksheets(Worksheet1).Activate
Sheets(Worksheet1).Copy
Main_wb.Worksheets("Current Q").Activate.Paste
'Do While Seek(6) <= LOF(6)
' Line Input #6, ResultStr
' numLines = numLines + 1
'Loop
Close #6
myFile2 = FolderPrevious & FilePrevious
Worksheet2 = FolderPrevious & FilePrevious
Open myFile2 For Input As #12
Worksheets(Worksheet).Activate
Sheets(Worksheet).Copy
Main_wb.Worksheets("Previous Q").Activate.Paste
Close #12
Main_wb.Worksheets("Start").Activate
Application.ScreenUpdating = True
End Function
Last edited by a moderator: