Vlookup not working as expected.

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks.

If I enter my vlookup... =VLOOKUP(O7,BudgetHours,2,FALSE)*U1 directly into a cell it works as expected. When I try to pass this... Range("D" & i).Formula = "=VLOOKUP(O & i & ,BudgetHours,2,False)*U1" I get thrown out of my routine. Here's the full snippet...

VBA Code:
lRow = Range("A" & Rows.Count).End(xlUp).Row
    For i = 3 To lRow
        With Range("O" & i)
            If .Font.Bold Then
                Range("D" & i).Formula = "=VLOOKUP(O & i & ,BudgetHours,2,False)*U1"
            End If
        End With
    Next
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
In VBA code, it is important to understand that everything between double-quotes will be treated as literal text.
So any variables you have must be outside of the double-quotes to be treated as a variable, i.e.
Excel Formula:
Range("D" & i).Formula = "=VLOOKUP(O" & i & ",BudgetHours,2,False)*U1"
 
Upvote 0
Solution
In VBA code, it is important to understand that everything between double-quotes will be treated as literal text. So any variables you have must be outside of the double quotes, i.e.
Excel Formula:
Range("D" & i).Formula = "=VLOOKUP(O" & i & ",BudgetHours,2,False)*U1"
I should have known better. Quotes give me headaches. -Thanks Joe.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,269
Messages
6,123,976
Members
449,138
Latest member
abdahsankhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top