Currently Running the below code, and need to make an edit to one part.
Sub VlookMultipleWorkbooks()
Dim lookFor As Range
Dim looktran As Range
Dim shipdate As Long
Dim srchRange As Range
Dim srchtran As Range
Dim lrow As Long
Dim lcol As Long
Dim dccol As Long
Dim sccol As Long
Dim transcol As Long
Dim shipcol As Long
Dim rowstart As Integer
Dim book1 As Workbook
Dim book2 As Workbook
Dim book2Name As String
book2Name = "DC_Data.xlsx" 'modify it as per your requirement
Dim book2NamePath As String
book2NamePath = "C:\Users\markf\OneDrive\" & book2Name
Set book1 = ThisWorkbook
If IsOpen(book2Name) = False Then Workbooks.Open (book2NamePath)
Set book2 = Workbooks(book2Name)
lcol = Cells(1, Columns.Count).End(xlToLeft).Column
dccol = lcol + 1
sccol = lcol + 2
transcol = lcol + 3
shipcol = lcol + 4
lrow = Cells(Rows.Count, 1).End(xlUp).Row
Cells(1, dccol).Value = "DC"
Cells(1, sccol).Value = "SCAC"
Cells(1, transcol).Value = "Transit Days"
Cells(1, shipcol).Value = "Ship Date"
rowstart = 2
Do While rowstart <= lrow
Set lookFor = book1.Sheets(1).Cells(rowstart, 3)
Set srchRange = book2.Sheets(1).Range("A:B")
Cells(rowstart, dccol).Value = Application.VLookup(lookFor, srchRange, 2, False)
Set looktran = book1.Sheets(1).Cells(rowstart, dccol)
Set srchtran = book2.Sheets(2).Range("A:C")
Cells(rowstart, sccol).Value = Application.VLookup(looktran, srchtran, 2, False)
Cells(rowstart, transcol).Value = Application.VLookup(looktran, srchtran, 3, False)
Cells(rowstart, shipcol).Formula = "=Workday(K" & rowstart & ",-2-" & Cells(rowstart, transcol).Value & ")"
rowstart = rowstart + 1
Loop
End Sub
Column K as referenced in the below formula may really not always be column K.
What I am looking to do is replace that with a variable that would be assigned a column based on specific text (say Stock) that would be in the header row of the data.
Cells(rowstart, shipcol).Formula = "=Workday(K" & rowstart & ",-2-" & Cells(rowstart, transcol).Value & ")"
How do I go about doing something like this?
Bookmarks