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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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
Hello Marcelo
Thank you for your help. In this case I will leave the formula in the cells.

Thanks
Marc
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,408
Members
449,448
Latest member
Andrew Slatter

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