Convert excel formula into VBA coding

Shweta

Well-known Member
Joined
Jun 5, 2011
Messages
514
Hi All,

I want below mentioned formula to be converted into VBA coding.


=INDEX(Sheet2!B$2:B$22,MATCH(1,IF(Sheet2!A$2:A$22=A2,IF(Sheet2!B$2:B$22>B2,1)),0))

Can someone please help me out.

I want to code this on command button.

Thanks,
Shweta
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Have you tried the macro recorder for that one?

If that doesn't work for you, then:
Have you told us everything we need to know about that formula? For example ..
- where it goes (sheet & cell)
- it looks like it may be an array formula, but you haven't mentioned that.
 
Upvote 0
Hi Shweta,

You can try EVALUATE() function to use the same formula directly, as follow:

Code:
Sub test
Var=EVALUATE("INDEX(Sheet2!B$2:B$22,MATCH(1,IF(Sheet2!A$2:A$22=A2,IF(Sheet2!B$2:B$22>B2,1)),0))")

End Sub

Hope this helps,

Regards
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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