Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I identify what cell was clicked on when I click on a butt

Is it possible to identify what cell was clicked on when I click on a button
to run a macro. I want to put about 10 buttons as column headers in a large
table. I would like to associate the same macro with each button and sort
based on which button (column) I click on. For example, with buttons,
"name", "city", "state", "zipcode", "product" all associated with the
"sorter" macro:
+------------+------------+------------+------------+------------+
| name | city | state | zipcode | product |
+------------+------------+------------+------------+------------+
j smith cupertino ca 95221 basket
a jones anaheim ca 93323 torch
p will las vegas nv 21352 basket
t adams reno nv 21992 bucket

I would like to click on the button and have the macro sort the respective
column. Does anyone have any idea how this can be done or even if it can be
done in Excel? Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How can I identify what cell was clicked on when I click on a butt

"san jose native" wrote in message
...
: Is it possible to identify what cell was clicked on when I click on a
button
: to run a macro. I want to put about 10 buttons as column headers in a
large
: table. I would like to associate the same macro with each button and sort
: based on which button (column) I click on. For example, with buttons,
: "name", "city", "state", "zipcode", "product" all associated with the
: "sorter" macro:
: +------------+------------+------------+------------+------------+
: | name | city | state | zipcode | product |
: +------------+------------+------------+------------+------------+
: j smith cupertino ca 95221 basket
: a jones anaheim ca 93323 torch
: p will las vegas nv 21352 basket
: t adams reno nv 21992 bucket
:
: I would like to click on the button and have the macro sort the respective
: column. Does anyone have any idea how this can be done or even if it can
be
: done in Excel? Thank you.

While it's not easy to tell what cell was clicked on (since you are clicking
a button in the cell), wouldn't you rather know what button was clicked on?
If you create 10 buttons, then each button would have it's own onclick event
that could then feed a range to a sort routine. If you would consider
double clicking a cell, then the doubleclick event could be used. Paste the
following in the sheet code module

Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, Cancel As
Boolean)
If target.Row = 1 Then
target.CurrentRegion.Sort Key1:=Range(target.Address),
Order1:=xlAscending, Header:= _
xlYes, OrderCustom:=1, Orientation:=xlTopToBottom
Cancel = True
End If
End Sub

Note this routine assumes you have a header row in row 1 of the worksheet.
If you double click any cell in row 1, it should sort the table based on
that row. If you want decending instead of Ascending, change order1. You
could also add key2, order2 and key3, order3 if you want a second or third
sort field.
Paul D


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default How can I identify what cell was clicked on when I click on a butt

Use Application.Caller to identify which button called the macro.

Sort accordingly.

Tim


"san jose native" wrote in
message ...
Is it possible to identify what cell was clicked on when I click on
a button
to run a macro. I want to put about 10 buttons as column headers in
a large
table. I would like to associate the same macro with each button
and sort
based on which button (column) I click on. For example, with
buttons,
"name", "city", "state", "zipcode", "product" all associated with
the
"sorter" macro:
+------------+------------+------------+------------+------------+
| name | city | state | zipcode | product
|
+------------+------------+------------+------------+------------+
j smith cupertino ca 95221 basket
a jones anaheim ca 93323 torch
p will las vegas nv 21352 basket
t adams reno nv 21992 bucket

I would like to click on the button and have the macro sort the
respective
column. Does anyone have any idea how this can be done or even if
it can be
done in Excel? Thank you.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default How can I identify what cell was clicked on when I click on a butt

Here's an old post.

I put rectangles over the headers (made the borders invisible) so that when you
clicked on the rectangle, it looked like you were clicking on the header.

Option Explicit
Sub setupOneTime()

Dim myRng As Range
Dim myCell As Range
Dim curWks As Worksheet
Dim myRect As Shape

Set curWks = ActiveSheet

With curWks
'10 columns
Set myRng = .Range("b1").Resize(1, 10)
For Each myCell In myRng.Cells
With myCell
Set myRect = .Parent.Shapes.AddShape _
(Type:=msoShapeRectangle, _
Top:=.Top, Height:=.Height, _
Width:=.Width, Left:=.Left)
End With
With myRect
.OnAction = ThisWorkbook.Name & "!SortTable"
.Fill.Visible = False
.Line.Visible = False
End With
Next myCell
End With
End Sub
Sub sortTable()

Dim myTable As Range
Dim myColToSort As Long
Dim curWks As Worksheet
Dim mySortOrder As Long
Dim LastRow As Long

Set curWks = ActiveSheet
With curWks
myColToSort = .Shapes(Application.Caller).TopLeftCell.Column
LastRow = .Cells(.Rows.Count, "b").End(xlUp).Row
Set myTable = .Range("b1:b" & LastRow).Resize(, 10)
If .Cells(myTable.Row + 1, myColToSort).Value _
< .Cells(LastRow, myColToSort).Value Then
mySortOrder = xlDescending
Else
mySortOrder = xlAscending
End If
myTable.Sort key1:=.Cells(myTable.Row, myColToSort), _
order1:=mySortOrder, _
header:=xlYes
End With

End Sub

san jose native wrote:

Is it possible to identify what cell was clicked on when I click on a button
to run a macro. I want to put about 10 buttons as column headers in a large
table. I would like to associate the same macro with each button and sort
based on which button (column) I click on. For example, with buttons,
"name", "city", "state", "zipcode", "product" all associated with the
"sorter" macro:
+------------+------------+------------+------------+------------+
| name | city | state | zipcode | product |
+------------+------------+------------+------------+------------+
j smith cupertino ca 95221 basket
a jones anaheim ca 93323 torch
p will las vegas nv 21352 basket
t adams reno nv 21992 bucket

I would like to click on the button and have the macro sort the respective
column. Does anyone have any idea how this can be done or even if it can be
done in Excel? Thank you.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
show the time I last saved my file just hovering a mouse on a butt Rajarshi Shrestha Excel Discussion (Misc queries) 0 April 7th 06 07:54 PM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM
intellimouse gone dirty-boy; restore backspace on outer left butt. Terminatrix Excel Discussion (Misc queries) 1 February 15th 05 06:27 AM
Is there a way to say which cell is clicked on? Jack Excel Programming 0 August 25th 04 05:11 PM
How to determine which button was clicked on the modified right-click menu Patrick Choi Excel Programming 1 September 1st 03 02:07 PM


All times are GMT +1. The time now is 07:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"