selecting cell using buttons

rishilaughs

New Member
Joined
Jun 10, 2013
Messages
6
Hi,

i am a newbie to macro and vb programming
i want to implement a small functionality of selecting a cell using buttons in a table
For E.g in a table like this
Column Button AColumn Button BColumn Button C
Row Button A131415
Row Button B161718
Row Button C192021

<tbody>
</tbody>
i wish if i click row button b and then click column button c i want value 18 to be selected to be used for further calculation.

I am trying to use worksheet function row, column, match ,index and also using Worksheet_BeforeDoubleClick event but don't seem to be reaching to the desired output.

Any help would be highly appreciated

Thanking in anticipation
Rishi
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi, and welcome to the forum.

This is a simple solution to give you an idea of how this could be done.

Declare two global variables:
Rich (BB code):
Public rw As Long       'row number
Public cell As String    'column letter

For each button create a click event. For example, the "row" buttons will update the row variable:
Rich (BB code):
Private Sub cmdRow1_Click()
   rw = 2
End Sub

The "column" buttons will assign the column letter, and add the row number.
Then it will call a test function to return the desired value:
Rich (BB code):
Private Sub cmdColA_Click()
   cell = "A" & rw
   
   'test
   MsgBox GetCellValue(cell)
End Sub

A simple function to get the value could be:
Rich (BB code):
Function GetCellValue(ByVal CellAddress As String) As Variant
   GetCellValue = Sheets("Sheet1").Range(CellAddress).Value
End Function

Hope this helps get you started.
Bertie
 
Upvote 0
Using activex buttons on the sheet, in the sheet's code module:
Code:
Dim Colm As Long, rw As Long
Private Sub CommandButton1_Click() 'Column B button
Colm = 2
selectme
End Sub

Private Sub CommandButton2_Click() 'Column C button
Colm = 3
selectme
End Sub

Private Sub CommandButton3_Click() 'Column D button
Colm = 4
selectme
End Sub

Private Sub CommandButton4_Click() 'row 2 button
rw = 2
selectme
End Sub

Private Sub CommandButton5_Click() 'row 3 button
rw = 3
selectme
End Sub

Private Sub CommandButton6_Click() 'row 4 button
rw = 4
selectme
End Sub
Sub selectme()
If rw > 0 And Colm > 0 Then Cells(rw, Colm).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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