Help required for translating formula to a VBA command

MSchädler

Board Regular
Joined
Apr 27, 2017
Messages
95
Hi
I'm using in my sheet the following formula in column R =if(Q2<>"",VLOOKUP(Q2,Sheet2!A:B,2,FALSE),"").
What it is doing is: if in column Q there is a "TEXT" and If the equivalent "TEXT" is found in Sheet2, column A, get value in column B.

It would be great to have the equivalent vba command to do this operation.
Thank you for any help.
M.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If you want to insert the formula in, for example, R2:R10 something like this

Code:
Range("R2:R10").Formula = "=IF(Q2<>"""",VLOOKUP(Q2,Sheet2!A:B,2,FALSE),"""")"

M.
 
Upvote 0
Hello again Marcelo
I believe that my question is not understood. I use the formula =if(Q2<>"",VLOOKUP(Q2,Sheet2!A:B,2,FALSE),"") in each cell in column R.
When the macro copies the last row it paste the formula as well.

In order to make my sheet more efficient i would like to replace this formula and use a VBA command instead and put it in my existing macro.
Any suggestion how that is done?

Here is the link to my drop box for a test sheet: https://www.dropbox.com/s/dodz8e3zrycae89/Macro_Test_P000-1.xlsm?dl=0

Marc
 
Upvote 0
Hello again Marcelo
I believe that my question is not understood. I use the formula =if(Q2<>"",VLOOKUP(Q2,Sheet2!A:B,2,FALSE),"") in each cell in column R.
When the macro copies the last row it paste the formula as well.

In order to make my sheet more efficient i would like to replace this formula and use a VBA command instead and put it in my existing macro.
Any suggestion how that is done?

Here is the link to my drop box for a test sheet: https://www.dropbox.com/s/dodz8e3zrycae89/Macro_Test_P000-1.xlsm?dl=0

Marc

Marc,

This formula is very efficient. No need of vba loop or Find method to do the job.
If you want to get rid of the formulas, after they do what they are supposed to do, and stay only with values, try this.

Code:
With Range("R2:R10")
    .Formula = "=IF(Q2<>"""",VLOOKUP(Q2,Sheet2!A:B,2,FALSE),"""")"
    .Value = .Value
End With

M.
 
Last edited:
Upvote 0
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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