VBA - Command button to run VLOOKUP formulae & also reset field button

xxweelinseyxx

New Member
Joined
Jul 8, 2018
Messages
3
Hi all, hoping someone can help me.

I have the VLOOKUP formulae prepared which works in a normal excel field (=VLOOKUP(Calc!$E$1,Calc!$B$2:$C$200,2,FALSE))

However, I want to add a command button, which when clicked will calculate the lookup formulae and put the result into Cell D10.

How do I do this?

Also - how do I create another command button which will effectively reset the same field D10 to blank(or zero) awaiting that the VLOOKUP button can then be ran again after that will override the blank/zero value.

Any help is appreciated.
Thanks
Linsey
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Linsey,

Usually buttons are used to run VBA code, not to have a cell formula calculate. The cell will “automatically” calculate when the workbook or worksheet is changed. Mind you I have the word in quotations because you can set this behavior any way you want to, it’s default setting is automatic.

Can you be more specific why you want a button to activate a function on a worksheet, maybe we can provide you with a more elegant solution.
 
Upvote 0
Hi Phil

It is for a club 'lottery type' monthly draw.

Basically each person pays a monthly charge to have their dedicated number in the draw. The paid up numbers are then entered into the draw (ie pasted into the 'Calc' worksheet with a second column attaching each number a random number using =rand and =rank functions.

Then on the 'Draw' worksheet, I have 6 blank cells/boxes. At present each of these 6 cells have a formula similar to (=VLOOKUP(Calc!$E$1,Calc!$B$2:$C$200,2,FALSE) in them, with a seperate command button which when clicked regenerates (ie recalculates the formula) 6 new lotto numbers in the 6 cells at once.

Howeve, what I have now been asked to do is have 6 separate buttons below each cell to generate the 6 lotto numbers separately (ie 6 different people can click togenerate a number to try replicate the old-style draw which involved 6 people drawing 6 balls from a tombola box).

Ultimately then a further button would be visible to 'Clear Draw' so that the 6 cells woul return to zero/blank so that the next draw is generated from blank cells and won't have numbers in them.

Hope this helps a little?
 
Upvote 0
How about
Code:
Sub Draw1()
Range("D10").Value = [VLOOKUP(calc!$E$1,calc!$B$2:$C$200,2,FALSE)]
End Sub
 
Upvote 0
When i done this for some reason when the button is clicked it is calculating new numbers in all six cells and not just 'D10' ??
 
Upvote 0
Did you change the button to look at the code I provided?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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