Hello,
I'm trying to Select a File with a static table with Allocation Data and then copy and paste the data in each workbook corresponding to the employee number after a vlookup of cell A2.
The first block of If statements is a file selector which returns the file path. I believe I'm referencing the file path and then activating the workbook after that but am not sure.
After that I am trying to loop through each workbook in the stated directory with a vlookup of the value in range A2 in each workbook and paste the value in the Selected File at the bottom of column A in the looped through workbook.
Below is the code that is giving me an Object 400 error.
Any help would be appreciated. Thanks .
I'm trying to Select a File with a static table with Allocation Data and then copy and paste the data in each workbook corresponding to the employee number after a vlookup of cell A2.
The first block of If statements is a file selector which returns the file path. I believe I'm referencing the file path and then activating the workbook after that but am not sure.
After that I am trying to loop through each workbook in the stated directory with a vlookup of the value in range A2 in each workbook and paste the value in the Selected File at the bottom of column A in the looped through workbook.
Below is the code that is giving me an Object 400 error.
VBA Code:
Sub allocationtransfer()
Dim DialogBox As FileDialog
Dim path As String
Set DialogBox = Application.FileDialog(msoFileDialogFilePicker)
DialogBox.Title = "Select file for " & FileType
DialogBox.Filters.Clear
DialogBox.Show
If DialogBox.SelectedItems.Count = 1 Then
path = DialogBox.SelectedItems(1)
End If
ThisWorkbook.Names("File_Path").RefersToRange.Value = path
ActiveWorkbooks.Activate
ActiveWorkbooks.Open
Dim ws As Worksheet
Dim wb As Workbook
CurDir = "C:\Users\Privacy\Privacy\Documents\Projects\PayrollTimeSheets\"
datarngtable = wb.ws.Range("A1:I22")
For Each wb In CurDir
Set tmws = ThisWorkbook.Worksheets("Time Cards")
LastRow = tmws.Range("A" & Rows.Count).End(xlUp).Row
LastRow.Offset(2, 0).Value = Application.WorksheetFunction.VLookup( _
tmws.Range("A2").Value, datarngtable, 2, False)
Next
End Sub
Any help would be appreciated. Thanks .