referencing a button on an activecell

aspiringnerd

New Member
Joined
Apr 22, 2022
Messages
39
Office Version
  1. 365
Platform
  1. Windows
I can use the following to reference a cell based on the location of the button

VBA Code:
ActiveSheet.Buttons(Application.Caller).TopLeftCell.Select

but can you do the opposite? I want to reference a button based on the active cell.

ie if I have cell a1 selected then I want to reference button 1, and if I have a2 selected then I want to reference button 2 (assuming each row gets a button)
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Why have all these buttons?
Why not double click A1 and a script will run.
double click A2 and a script will run. And on and on.
If this would work let me know what you want to happen when you double, click on Range A1 and on and on.
 
Upvote 0
Why have all these buttons?
Why not double click A1 and a script will run.
double click A2 and a script will run. And on and on.
If this would work let me know what you want to happen when you double, click on Range A1 and on and on.
I'd like a button to be dependent on if an xlookup return is true. The only way I thought of doing it is to always have a button but hidden and only shows when xlookup (via VBA) returns a value. The button will always have the same script.
 
Upvote 0
I would not be able to help with this.
Maybe someone else here will be able to help you.
Showing and hiding a large number of buttons is not something I would suggest.

You said:
"assuming each row gets a button)"

There are nearly 1.5 million rows having 1.5 million buttons would be difficult.
 
Upvote 0
I would not be able to help with this.
Maybe someone else here will be able to help you.
Showing and hiding a large number of buttons is not something I would suggest.

You said:
"assuming each row gets a button)"

There are nearly 1.5 million rows having 1.5 million buttons would be difficult.

Max 1000, I've already solved that part tho. I just need to reference a button based on the cell it's in, not based on what it is called.
 
Upvote 0
I would not be able to help with this.
Maybe someone else here will be able to help you.
Showing and hiding a large number of buttons is not something I would suggest.

You said:
"assuming each row gets a button)"

There are nearly 1.5 million rows having 1.5 million buttons would be difficult.
I guess another route is to just create the button and attach the macro...I'll give it a try in the morning
 
Upvote 0
You said:
"The button will always have the same script."

Show me the script you will have in the button.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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