Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
Hi,
I am working on a macro in Excel 2003 Pro, and everytime I go to sort a column of data. There are about 10 rows of data in about 200+ columns. I can only get the macro to sort the column that I edited it with. How can I create the macro, so each time I click on the first row of each column, click the macro button I will assign to the toolbar, then that row will be sorted, and do this for each column? Any help at all would be greatly appreciated, Jeff Garrett ) |
#2
![]() |
|||
|
|||
![]()
Hi Jeff
please post your current code and then we can suggest changes to it. Cheers JulieD "Jeff Garrett" <Jeff wrote in message ... Hi, I am working on a macro in Excel 2003 Pro, and everytime I go to sort a column of data. There are about 10 rows of data in about 200+ columns. I can only get the macro to sort the column that I edited it with. How can I create the macro, so each time I click on the first row of each column, click the macro button I will assign to the toolbar, then that row will be sorted, and do this for each column? Any help at all would be greatly appreciated, Jeff Garrett ) |
#3
![]() |
|||
|
|||
![]() Sub Sort()'where sortrange is a named range to sort a1:aa200 [SortRangeAdd].Sort Key1:=Cells(1, activecell.column), Order1:=xlAscending, Orientation:=xlTopToBottom End Sub -- Don Guillett SalesAid Software "Jeff Garrett" <Jeff wrote in message ... Hi, I am working on a macro in Excel 2003 Pro, and everytime I go to sort a column of data. There are about 10 rows of data in about 200+ columns. I can only get the macro to sort the column that I edited it with. How can I create the macro, so each time I click on the first row of each column, click the macro button I will assign to the toolbar, then that row will be sorted, and do this for each column? Any help at all would be greatly appreciated, Jeff Garrett ) |
#4
![]() |
|||
|
|||
![]()
posting your code would help.
Macros do not respond to mouse clicks or other forms of input divices. the code replaces all these. mouse clicks can trigger code to run but they can't be used as code parameters. you might try in the code to sort by Activecell but i have never tried that and am not too sure it would work. -----Original Message----- Hi, I am working on a macro in Excel 2003 Pro, and everytime I go to sort a column of data. There are about 10 rows of data in about 200+ columns. I can only get the macro to sort the column that I edited it with. How can I create the macro, so each time I click on the first row of each column, click the macro button I will assign to the toolbar, then that row will be sorted, and do this for each column? Any help at all would be greatly appreciated, Jeff Garrett ) . |
#5
![]() |
|||
|
|||
![]()
Sub Macro1()
Dim varColumn As String Dim varNo As String For varColumn = "A" To "IV" varNo = varColumn & 1 Range([varNo]).Select Application.CutCopyMode = False Selection.Sort Key1:=Range(ActiveCell, ActiveCell.End(xlUp)).Select, Order1:=xlDescending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Next varColumn End Sub Basically, I want to go from Cell B1 to Cell IV1, and call this macro to sort the column that is currently selected descendingly. It will be all integers, some non-entries representing a 0. The whole reason to do a macro is because there is like 200 entries in the worksheet. Any and all suggestions are welcome. |
#7
![]() |
|||
|
|||
![]()
Yes. Sort each column individually. Then, iterate over each column. Do I
have to dim lc, lr as variables? What kind though? String? Char? |
#8
![]() |
|||
|
|||
![]()
Order1:=xlAscending
This means ascending order (lowest to highest) right? I want descending order. So I put this: Order1:=xlDescending Correct? |
#9
![]() |
|||
|
|||
![]()
Yes, try it.
-- Don Guillett SalesAid Software "Jeff Garrett" wrote in message ... Order1:=xlAscending This means ascending order (lowest to highest) right? I want descending order. So I put this: Order1:=xlDescending Correct? |
#10
![]() |
|||
|
|||
![]()
That's worked Don. The only problem is it's doing too much. It should only
sort rows 2-12 inclusive, and this is what we last came up with: lr = Cells(Rows.Count, i).End(xlUp).Row This does too much. How do you do only sort the rows 2-12? |
#11
![]() |
|||
|
|||
![]()
It is sorting row 2 - 12 if 12 is the last row with data. It would be 234 if
that was the last row with data. I thought you wanted it to be adaptable for the amount of date in each column. If not, change to 12..... -- Don Guillett SalesAid Software "Jeff Garrett" wrote in message ... That's worked Don. The only problem is it's doing too much. It should only sort rows 2-12 inclusive, and this is what we last came up with: lr = Cells(Rows.Count, i).End(xlUp).Row This does too much. How do you do only sort the rows 2-12? |
#12
![]() |
|||
|
|||
![]()
So lc must be the last row with acceptable data. It makes sense now.
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
select worksheet to run macro | Excel Discussion (Misc queries) | |||
Removing Unnecessary Macro Security Warnings | Excel Discussion (Misc queries) | |||
search macro | Excel Discussion (Misc queries) | |||
Macro for Show/Hide Column | Excel Discussion (Misc queries) | |||
This one is tricky....Macro to save file as cell value x in di | Excel Discussion (Misc queries) |