Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default sort dynamic range on active cell

Hi there

is there anyway to sort a dynamic range (ie amount of columns and rows may
vary) based on the column of the active cell. to make things even more
complicated i would like to have a button that when you click it the data is
sorted ascending and if you click it again it is descending)

Examle:
Name, age, class, height = col headings
if i click a in any cell in col b (age) then click button it sorts data
ascending, click again and its descending
If i then select a cell in col d (height) i can sort that col based on
active cell being in it

i hope there is a neat way of doing this.

Appreciate any help in this regard

Thanks
Kev
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default sort dynamic range on active cell

You can try this to see if it works like you expect. I used Range("F2") as
the control range. You can change it to another obscure range by canging
the cell reference in the code.

Sub CommandButton1_Click()
Dim rng As Range, lr As Long
Dim sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:D" & lr)
sel = Selection.Address
If Range("F2").Value < "Down" Then
rng.Sort Range(sel), xlAscending
sh.Range("F2") = "Down"
Else
rng.Sort Range(sel), xlDescending
sh.Range("F2") = "Up"
End If
End Sub




"kevin" wrote in message
...
Hi there

is there anyway to sort a dynamic range (ie amount of columns and rows may
vary) based on the column of the active cell. to make things even more
complicated i would like to have a button that when you click it the data
is
sorted ascending and if you click it again it is descending)

Examle:
Name, age, class, height = col headings
if i click a in any cell in col b (age) then click button it sorts data
ascending, click again and its descending
If i then select a cell in col d (height) i can sort that col based on
active cell being in it

i hope there is a neat way of doing this.

Appreciate any help in this regard

Thanks
Kev



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default sort dynamic range on active cell

I assumed you knew how to put a command button from the Control Toolbox on
the sheet and then put the code in the sheet code module. That will be
necessary for you to utilize the code provided.


"kevin" wrote in message
...
Hi there

is there anyway to sort a dynamic range (ie amount of columns and rows may
vary) based on the column of the active cell. to make things even more
complicated i would like to have a button that when you click it the data
is
sorted ascending and if you click it again it is descending)

Examle:
Name, age, class, height = col headings
if i click a in any cell in col b (age) then click button it sorts data
ascending, click again and its descending
If i then select a cell in col d (height) i can sort that col based on
active cell being in it

i hope there is a neat way of doing this.

Appreciate any help in this regard

Thanks
Kev



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default sort dynamic range on active cell

Thanks JLGWhiz

I've been searching the boards for code to run that private sub you posted
when i click on the command button but no luck. how do i call the procedure.
do need option explicit or to dim stuff as public.

Hope you can help

Kev
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
getting the selected range and active cell of a non active worksheetsheet GerryGerry Excel Programming 7 September 23rd 09 05:22 PM
Sort Dynamic Range lightjag Excel Programming 4 March 21st 09 09:00 PM
I need to sort an active sheet using the col of the active cell HamFlyer Excel Programming 3 June 6th 06 07:25 PM
Dynamic column chart - auto sort on data range jimfrog Charts and Charting in Excel 0 March 29th 06 02:45 PM
Active / Dynamic Filtered List (changes w/ change in cell value) [email protected] Excel Discussion (Misc queries) 3 March 31st 05 04:03 PM


All times are GMT +1. The time now is 07:04 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"