khalari808
New Member
Hi, Need help.
I found this great code that works; however, I need to modify it a little to fit my needs.
How can I include an IF then condition. If target sheet Column C contains a text string ("Labor" or "Materials") then it performs the Vlookup otherwise skips to the next cell.
I found this great code that works; however, I need to modify it a little to fit my needs.
How can I include an IF then condition. If target sheet Column C contains a text string ("Labor" or "Materials") then it performs the Vlookup otherwise skips to the next cell.
Code:
Sub MakeFormulas()
Dim SourceLastRow As Long
Dim OutputLastRow As Long
Dim sourceSheet As Worksheet
Dim outputSheet As Worksheet
'What are the names of our worksheets?
Set sourceSheet = Worksheets("Sheet1")
Set outputSheet = Worksheets("Sheet2")
'Determine last row of source
With sourceSheet
SourceLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With outputSheet
'Determine last row in col P
OutputLastRow = .Cells(.Rows.Count, "P").End(xlUp).Row
'Apply our formula
.Range("Q2:Q" & OutputLastRow).Formula = _
"=VLOOKUP(A2,'" & sourceSheet.Name & "'!$A$2:$B$" & SourceLastRow & ",2,0)"
End With
End Sub