jassybun
Member
Hello amazing people, I am learning so much, thank you - I have another question - how to I add a header name to each of these loops? altogether I am creating 4 columns but they don't have header names.
Instructions: https://chandoo.org/forum/threads/posting-a-sample-workbook.451/
Instructions: https://chandoo.org/forum/threads/posting-a-sample-workbook.451/
Code:
Sub Lookup1()
Dim rng As Range
Dim c As Range
Dim result As Variant
Set rng = Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
For Each c In rng.Cells
result = Application.WorksheetFunction.VLookup(c.Value, Workbooks("Lookup1.xlsx").Worksheets("Sheet1").Range("A2:C350"), 2, False)
If IsError(result) Then
c.Offset(, 12) = "Not Found"
Else
c.Offset(, 12).Value = result
End If
Next c
For Each c In rng.Cells
result = Application.WorksheetFunction.VLookup(c.Value, Workbooks("Lookup1.xlsx").Worksheets("Sheet1").Range("A2:C350"), 3, False)
If IsError(result) Then
c.Offset(, 13) = "Not Found"
Else
c.Offset(, 13).Value = result
End If
Next c
For Each c In rng.Cells
result = Application.WorksheetFunction.VLookup(c.Value, Workbooks("Lookup1.xlsx").Worksheets("Sheet1").Range("A2:d350"), 4, False)
If IsError(result) Then
c.Offset(, 14) = "Not Found"
Else
c.Offset(, 14).Value = result
End If
Next c
With rng.Offset(, 15)
.Value = Evaluate("IF(" & .Offset(, -13).Address & "-(" & .Offset(, -14).Address & "+TIMEVALUE(" & .Offset(, -5).Address & ")+IF(" & .Offset(, -4).Address & "=""PM"",0.5,0))>1,""Yes"",""No"")")
End With
End Sub
Last edited by a moderator: