PDA

View Full Version : Vba Code Automatically Sort Rows Large To Small



etheer
03-16-2013, 01:29 PM
I Need Help Vba Code Automatically Sort Rows Large To Small By Data In Column D

SamT
03-16-2013, 03:35 PM
First record a macro of you manually doing the sort, then post the macro code here do we can help you clean it up and refine it.

etheer
03-16-2013, 05:18 PM
you download book1s.xlsx

SamT
03-16-2013, 07:36 PM
I did.

You record macro

etheer
03-18-2013, 03:40 PM
Hi SamT
i have this macro you can edit it
this macro skip cells 0
i need also sort data large to small
i hope you can help me


Private Sub Hide_Unhide()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 7 To 111
Rows(i).Hidden = (Cells(i, "J").Value = 0) + (Cells(i, "b").Value = "")
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

SamT
03-18-2013, 03:58 PM
What is the range of the entire table you need sorted?
Example Answer: A7 to J111

etheer
03-18-2013, 04:07 PM
Sort Large To Small By Data In Column D

etheer
03-18-2013, 04:09 PM
Private Sub Hide_Unhide()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 4 To 500
Rows(i).Hidden = (Cells(i, "D").Value = 0) + (Cells(i, "F").Value = "")
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

SamT
03-18-2013, 04:16 PM
Sort what?

What is the range of the entire table you need sorted?
Example Answer: A7 to J111

etheer
03-18-2013, 04:26 PM
Sort what?
Samt please download book1macro

I need Sort data in column D large to small

SamT
03-18-2013, 04:30 PM
Range("A3:D111").Sort.( _
Key1:=Range("D3"), _
Order1:= xlDescending, _
Header:= xlNo)

etheer
03-18-2013, 04:34 PM
is impossible sort data in column D ?

etheer
03-18-2013, 04:39 PM
Range("A3:D111").Sort.( _
Key1:=Range("D3"), _
Order1:= xlDescending, _
Header:= xlNo)



thank you SamT
you can edit book1macro.xlsx and upload it agian
plases

SamT
03-18-2013, 05:52 PM
Range("D:D").Sort.( _
Key1:=Range("D1"), _
Order1:= xlDescending, _
Header:= xlGuess)

etheer
03-19-2013, 07:30 AM
Range("D:D").Sort.( _
Key1:=Range("D1"), _
Order1:= xlDescending, _
Header:= xlGuess)
how use this code in book1macro.xlsm ?:banghead:

SamT
03-19-2013, 02:17 PM
You need to start using the help files. In VBA, put the cursor in a word you want help on and press F1.

You might get better help by using the Non English Help Forum.


Private Sub Hide_Unhide()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 4 To 500
Rows(i).Hidden = (Cells(i, "D").Value = 0) + (Cells(i, "F").Value = "")
Next i

'Sorting only one column of a table will mess up the table.
'Change "D:D" to refelect the entire table.
Range("D:D").Sort _
Key1:=Range("D1"), _
Order1:=xlDescending, _
Header:=xlGuess

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Aussiebear
03-19-2013, 03:46 PM
There's a couple of good points that arise out of this thread that need to be made.

Firstly, simply by demanding that others download a workbook from the forum to solve an issue is not good ethics. There's a risk involved when downloading and opening a workbook from someone you don't know or yet trust.

Secondly, the underlying concept of the forum is to assist others to learn the VBA language and its usage, through both the offerings of sections of code, and or the request to supply a section of code that has been self produced.

Thirdly, all offers to assist are done by volunteers who give freely of their time. So to make the most of these offers, one needs to be prepared to make the issue as clear as possible by definition. Provide workbooks with working samples of data and provide examples of what has been tried. Then those wanting to assist are in a better position to work on a solution.

SamT
03-19-2013, 05:58 PM
Thank you, mod.

etheer
03-19-2013, 07:11 PM
You need to start using the help files. In VBA, put the cursor in a word you want help on and press F1.

You might get better help by using the Non English Help Forum.


Private Sub Hide_Unhide()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 4 To 500
Rows(i).Hidden = (Cells(i, "D").Value = 0) + (Cells(i, "F").Value = "")
Next i

'Sorting only one column of a table will mess up the table.
'Change "D:D" to refelect the entire table.
Range("D:D").Sort _
Key1:=Range("D1"), _
Order1:=xlDescending, _
Header:=xlGuess

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub



Thank you so much SamT