Selecting cell below command button

dshadel

New Member
Joined
Aug 2, 2007
Messages
17
Hi, I am working with a sheet where I will have multiple command buttons that will run the same macro in multiple areas (different rows and columns) of the same sheet. I would like to only have one macro - but I am at a loss as to how to make sure the proper cell is active before the rest of the macro runs.

Using VB code, how can I select the cell directly below - relative to the cell that the command button is located in?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If your CommandButton is from the Forms ToolBar, you can get the cell below it like this:

Code:
Sub Test()
    MsgBox ActiveSheet.Buttons(Application.Caller).TopLeftCell.Offset(1, 0).Address
End Sub
 
Upvote 0
The command buttons will be objects in the worksheet, for instance in cell B2 will be a button that will run a macro to input data in cell B3. Another button might be in cell d3 to input data in cell d4. The problem I encounter is that if cell a1 is selected and I push the button in cell b2, the data is entered in cell a1 instead of b3. I can not figure out how to set the active cell relative to the cell the control is in.
 
Upvote 0
This worked for me:

Code:
Sub Test()
    ActiveSheet.Buttons(Application.Caller).TopLeftCell.Offset(1, 0).Value = "Whatever"
End Sub
 
Upvote 0
Hello,

What if your button is a command button and not from the forms menu. Is there code to perform this same function? Thanks,



If your CommandButton is from the Forms ToolBar, you can get the cell below it like this:

Code:
Sub Test()
    MsgBox ActiveSheet.Buttons(Application.Caller).TopLeftCell.Offset(1, 0).Address
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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