jordsbaker
New Member
- Joined
- Apr 3, 2018
- Messages
- 5
Hi Team Amazing,
I need some help.
I have a sub that allows users to select a workbook and then open it. I then prompt them to select the tab that contains the data required.
I then want to copy all of the data from this tab and paste it into the workbook where the Sub is located.
However, everytime I get to the part of activating the chosen tab (selected through an Input box) I get a Subscript out of Range Error.
I assumed that this was because of the variables so have made them public but still get the error.
When I run I get all the way through the part where I want to select the sheet (with name saved as Tabname).
I have tried to run from Sub Importmix() with the file path saved directly into Path2 opposed to selecting it in Sub Test() but still get the error.
Please help.
Public tabname As String
Public ActiveSheet1 As Worksheet
Public path2 As String
Sub test()
Dim intResult As Integer
'Dim path As String
Dim fD As FileDialog
Set fD = Application.FileDialog(msoFileDialogFilePicker)
With fD
.Title = "Select a Path"
.AllowMultiSelect = False
.Show
End With
'importmix fD.SelectedItems(1)
path2 = fD.SelectedItems(1)
Call Importmix
End Sub
Sub Importmix()
Dim DataToCopy As Range
Dim FirstColumn As Range
Dim FirstColumnLetter As String
Dim LastColumn As Range
Dim LastColumnLetter As String
Dim LastRow As Long
Dim Firstrow As Long
Dim tabname As String
Workbooks.Open (path2)
tabname = InputBox("What is the name of the Tab holding the learning records?")
Workbooks(path2).Activate
Worksheets(tabname).Select
End Sub
I need some help.
I have a sub that allows users to select a workbook and then open it. I then prompt them to select the tab that contains the data required.
I then want to copy all of the data from this tab and paste it into the workbook where the Sub is located.
However, everytime I get to the part of activating the chosen tab (selected through an Input box) I get a Subscript out of Range Error.
I assumed that this was because of the variables so have made them public but still get the error.
When I run I get all the way through the part where I want to select the sheet (with name saved as Tabname).
I have tried to run from Sub Importmix() with the file path saved directly into Path2 opposed to selecting it in Sub Test() but still get the error.
Please help.
Public tabname As String
Public ActiveSheet1 As Worksheet
Public path2 As String
Sub test()
Dim intResult As Integer
'Dim path As String
Dim fD As FileDialog
Set fD = Application.FileDialog(msoFileDialogFilePicker)
With fD
.Title = "Select a Path"
.AllowMultiSelect = False
.Show
End With
'importmix fD.SelectedItems(1)
path2 = fD.SelectedItems(1)
Call Importmix
End Sub
Sub Importmix()
Dim DataToCopy As Range
Dim FirstColumn As Range
Dim FirstColumnLetter As String
Dim LastColumn As Range
Dim LastColumnLetter As String
Dim LastRow As Long
Dim Firstrow As Long
Dim tabname As String
Workbooks.Open (path2)
tabname = InputBox("What is the name of the Tab holding the learning records?")
Workbooks(path2).Activate
Worksheets(tabname).Select
End Sub