Macro to move cursor to letter in column

Canoer

New Member
Joined
Aug 4, 2023
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
I am using Excel 2013. In this worksheet there is a column with single letters A thru Z. There are buttons labeled A thru Z. For example there is a button on the sheet labeled "C". I want a macro so that when I click "Button C", it will move the cursor down the column until it arrives at the letter "C" in the column, and stop there. Is this possible?

Any help would be appreciated. Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I think it matters if the buttons are ActiveX controls or not. If so, perhaps something like this?
VBA Code:
Private Sub CommandButton1_Click()
Dim rng As Range

Set rng = Cells.Find(What:=CommandButton1.Caption, LookIn:=xlValues, Lookat:=xlWhole)
If Not rng Is Nothing Then
    rng.Select
End If
End Sub
If you have 26 of these buttons I would suggest using another way. One would be to place that in a standard module so that any button can call it. You'd still need an event for all 26 buttons though. Another might be to write one class that captures all button clicks but I have nothing for that.

If your buttons are not ActiveX controls then that code won't work and I have no idea if a class will work with form controls but I think not.
To refer to the text shown in a form control and use that in the What part is more like
What:=Sheets("SheetNameHere").Shapes("Button Name Here").TextFrame.Characters.Text

I find that for some very odd reason the button name is not what Excel uses in the beginning line of the sub. F'rinstance I would see
Sub MASTER_Button1_Click
but the given button name is "Button 1". If you try to use what's shown you'll end up very frustrated.
 
Upvote 0
Solution

Forum statistics

Threads
1,221,497
Messages
6,160,150
Members
451,626
Latest member
sukhman

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