excelnoob09
New Member
- Joined
- Apr 25, 2018
- Messages
- 4
Hi, I have spent two days googling and searching old threads to no avail so I'm posting here in hopes that someone can help.
I'm trying to automate 2 vlookups using VBA. I will receive reports daily where will we have to do vlookups to pull the advisor name and program name. So I have 2 worksheets in the workbook, sheet 1 where I will paste the report and add 2 columns to pull in the advisor and program. Sheet 2 is named "CRM Report" and that's the report where the advisor and program lives, in columns 5 and 6 respectively- I named the array 'adv'. The ID is column A in Sheet 1 and sheet 2 and that's what I am using as the lookup value. So the Vlookup formula is-
=vlookup(A2, adv,5,0)n - to pull the advisor name
&
= vlookup(A2, adv,6,0) - to pull the program name
here is the first formula that did not work-
Sub Vlookup()
Range("A2") = Application.WorksheetFunction.Vlookup("A2:A", Worksheets("CRM Report").adv, 5, False)
End Sub
I also tried this-
Sub Advisor()
'
' Advisor Macro
' advisor vlookup
'
'
Dim LR As Long
Sheets("CRM Report").Activate
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("O2").FormulaR1C1 = "=VLOOKUP(RC[-2],adv,5,0)"
Range("O2").AutoFill Destination:=Range("B2:B" & LR)
End Sub
Dim LR As Long
Sheets("CRM Report").Activate
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("O2").FormulaR1C1 = "=VLOOKUP(RC[-3],adv,6,0)"
Range("O2").AutoFill Destination:=Range("C2:C" & LR)
End Sub
Thank you in advance for any help.
I'm trying to automate 2 vlookups using VBA. I will receive reports daily where will we have to do vlookups to pull the advisor name and program name. So I have 2 worksheets in the workbook, sheet 1 where I will paste the report and add 2 columns to pull in the advisor and program. Sheet 2 is named "CRM Report" and that's the report where the advisor and program lives, in columns 5 and 6 respectively- I named the array 'adv'. The ID is column A in Sheet 1 and sheet 2 and that's what I am using as the lookup value. So the Vlookup formula is-
=vlookup(A2, adv,5,0)n - to pull the advisor name
&
= vlookup(A2, adv,6,0) - to pull the program name
here is the first formula that did not work-
Sub Vlookup()
Range("A2") = Application.WorksheetFunction.Vlookup("A2:A", Worksheets("CRM Report").adv, 5, False)
End Sub
I also tried this-
Sub Advisor()
'
' Advisor Macro
' advisor vlookup
'
'
Dim LR As Long
Sheets("CRM Report").Activate
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("O2").FormulaR1C1 = "=VLOOKUP(RC[-2],adv,5,0)"
Range("O2").AutoFill Destination:=Range("B2:B" & LR)
End Sub
Dim LR As Long
Sheets("CRM Report").Activate
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("O2").FormulaR1C1 = "=VLOOKUP(RC[-3],adv,6,0)"
Range("O2").AutoFill Destination:=Range("C2:C" & LR)
End Sub
Thank you in advance for any help.