How to sort in excel i have folowing data and i want highlighted columns can be sorted?

trustmeasfrnd

New Member
Joined
Oct 19, 2008
Messages
32
i want to sort corresponding to column O and T using macro button for ascending/descending values. the problem is my column A has Plate mark only for one case till all load cases changes. how to add plate mark in all rows(may be needed another excel Macro button to do that)
Also note that row can be more than shown here.
one more help needed can i reduce using formula for columns K L M N O and P Q R S T and rows as same formula is repeted?

Thanks in Advance.
ABCDEFGHIJKLMNOPQRST
1ShearMembraneBending MomentMxd For TOP REINFORCEMENTMxd For BOTTOM REINFORCEMENT
2PlateL/CSQX (local) N/mm2SQY (local) N/mm2SX (local) N/mm2SY (local) N/mm2SXY (local) N/mm2Mx kNm/mMy kNm/mMxy kNm/mMx1My1Mx2My2MxdMx1My1Mx2My2Mxd
31422301 1.5DL1 + 1.5LL0.0160.028-0.1836.7390.039-0.1446.778-0.182776.7473110.000-0.2226.7-0.183236.730689-0.183
4302 1.2DL1 + 1.2LL + 1.2WLX (W-E)0.0240.033-0.001-0.001-0.001-1.0717.9510.552-0.5198.503-1.032688.2355040.000-1.6237.399-1.109327.666496-1.109
5303 1.2DL1 + 1.2LL - 1.2WLX (W-E)0.0010.0110.0010.7992.813-0.4891.2883.3020.8840063.1122751.2880.312.3240.7139942.5137250.000
6304 1.2DL1 + 1.2LL + 1.2WLZ (N-S)0.0110.02-0.1714.031-0.7050.5344.736-0.04776.9375790.534-0.8763.326-0.29431.124421-0.294
7305 1.2DL1 + 1.2LL - 1.2WLZ (N-S)0.0140.024-0.076.8060.8110.7417.6170.02663816.202010.741-0.8815.995-0.16664-2.59001-0.167
8310 1.5DL1 + 1.5WLX (W-E)0.0290.04-0.001-0.001-0.001-1.2669.6380.595-0.67110.233-1.229279.9176410.000-1.8619.043-1.302739.358359-1.303
91419301 1.5DL1 + 1.5LL0.030.050.0020.0021.28976.4931.9413.2378.4341.33825379.415793.230-0.65274.5521.23974773.570211.240
10302 1.2DL1 + 1.2LL + 1.2WLX (W-E)0.0370.0470.001-0.0020.002-0.21488.5633.2443.0391.807-0.09517137.73843.030-3.45885.319-0.3328339.3876-0.333
11303 1.2DL1 + 1.2LL - 1.2WLX (W-E)0.0110.0320.0030.0030.0012.31433.214-0.0212.33533.2352.31401333.214192.3352.29333.1932.31398733.213810.000
12304 1.2DL1 + 1.2LL + 1.2WLZ (N-S)0.0260.0360.002-0.0010.002-0.42252.257-2.3461.92454.603-0.3166865.298981.924-2.76849.911-0.5273239.21502-0.527
13305 1.2DL1 + 1.2LL - 1.2WLZ (N-S)0.0220.0430.0020.0020.0012.48570.8125.6618.14676.4732.93756383.708158.146-3.17665.1512.03243757.915852.032
141417301 1.5DL1 + 1.5LL-0.055-0.2070.008-0.0080.00411.552107.0169.60221.154116.61812.41354114.997221.1541.9597.41410.6904699.034840.000
15302 1.2DL1 + 1.2LL + 1.2WLX (W-E)-0.049-0.1880.006-0.010.0079.38126.2137.36916.749133.5829.810242132.002116.7492.011118.8448.949758120.42390.000
16303 1.2DL1 + 1.2LL - 1.2WLX (W-E)-0.039-0.1430.006-0.003-0.0029.10243.9738.18617.28852.15910.625951.3351817.2880.91635.7877.57809736.610820.000
17304 1.2DL1 + 1.2LL + 1.2WLZ (N-S)-0.034-0.1690.006-0.0140.0047.06254.595.99413.05660.5847.72014359.6775213.0561.06848.5966.40385749.502480.000
18305 1.2DL1 + 1.2LL - 1.2WLZ (N-S)-0.054-0.1620.0060.0010.00211.401117.2669.54120.942126.80712.17728125.250420.9421.86107.72510.62472109.28160.000
191413301 1.5DL1 + 1.5LL0.035-0.033-0.001-0.001-2.3463.9222.5840.2386.506-0.643546.7681450.238-4.931.338-4.048461.075855-4.048
20302 1.2DL1 + 1.2LL + 1.2WLX (W-E)0.047-0.044-0.001-0.001-0.001-3.6326.8541.358-2.2748.212-3.362947.3617540.000-4.995.496-3.901066.346246-3.901
21303 1.2DL1 + 1.2LL - 1.2WLX (W-E)0.009-0.0080.001-0.001-0.097-0.7072.8182.7212.11111.1351481.160262.721-2.915-3.525-11.3291-82.5743-2.915
22304 1.2DL1 + 1.2LL + 1.2WLZ (N-S)0.024-0.028-0.001-0.001-1.9293.8823.0761.1476.9580.5083468.7870161.147-5.0050.806-4.36635-1.02302-4.366
23305 1.2DL1 + 1.2LL - 1.2WLZ (N-S)0.031-0.025-0.0010.001-0.002-1.8372.411.055-0.7823.465-1.375163.0158930.000-2.8921.355-2.298841.804107-2.299

<tbody>
</tbody>
Cenrral Force for MY

Worksheet Formulas
CellFormula
K3=H3+ABS(J3)
L3=I3+ABS(J3)
M3=H3+ABS(J3^2/I3)
N3=I3+ABS(J3^2/H3)
O3=IF(AND(K3>0,L3>0),K3,IF(AND(K3<0,L3<0),0,IF(AND(K3<0,L3>0),0,M3)))
P3=H3-ABS(J3)
Q3=I3-ABS(J3)
R3=H3-ABS(J3^2/I3)
S3=I3-ABS(J3^2/H3)
T3=IF(AND(P3>0,Q3>0),0,IF(AND(P3<0,Q3<0),P3,IF(AND(P3<0,Q3>0),R3,0)))

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited by a moderator:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
seems either its too easy or too hard.

ok, i was able to do two things first to fill empty cells for plate no. by providing following codes which i am still not sure if it will be general one:-
--------------------------------------------------------------------------------
Sub FillRow()
Dim Name As String
For Each c In Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
If Cells(c.Row, 1) > "" Then
Name = Cells(c.Row, 1).Value
Cells(c.Row, 1).Copy
Else
Cells(c.Row, 1).Value = Name
Cells(c.Row, 1).PasteSpecial (xlPasteFormats)
End If
Next
End Sub
-----------------------------------------------------------------------
This copy empty cells under COLUMN A till value changes or there is empty row ie last row.
Another thing that i was able to sort out was Formula repetition by using below code but i think it can be generalised as well, below is the code that i used,help appreciated to make it better
--------------------------
Sub FillDown()


Dim strFormulas(1 To 5) As Variant


With ThisWorkbook.Sheets("Sheet5")
strFormulas(1) = "=(H3+ABS(J3))"
strFormulas(2) = "=(I3+ABS(J3))"
strFormulas(3) = "=(H3+ABS(J3^2/I3))"
strFormulas(4) = "=(I3+ABS(J3^2/H3))"
strFormulas(5) = "=IF(AND(K3>0,L3>0),K3,IF(AND(K3<0,L3<0),0,IF(AND(K3<0,L3>0),0,M3)))"


.Range("k3:eek:3").Formula = strFormulas
.Range("k3:eek:5").FillDown
End With


End Sub
-----------------------------------------------------------
this formula currently has been done for column K3 to O5. Now it also needs to be generalised till last row, please help how to code it better.
there after i will b stuck to sort data with respect to column O.

Any leads will be useful.
thanks and regards.
Abhisekh
 
Upvote 0
This works on the activesheet & replaces both codes you supplied
Code:
Sub FillPlate()
   
   Dim strFormulas(1 To 5) As Variant
   
   strFormulas(1) = "=(H3+ABS(J3))"
   strFormulas(2) = "=(I3+ABS(J3))"
   strFormulas(3) = "=(H3+ABS(J3^2/I3))"
   strFormulas(4) = "=(I3+ABS(J3^2/H3))"
   strFormulas(5) = "=IF(AND(K3>0,L3>0),K3,IF(AND(K3<0,L3<0),0,IF(AND(K3<0,L3>0),0,M3)))"

   With Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
      
   Range("k3:O" & Range("J" & Rows.Count).End(xlUp).Row).Formula = strFormulas


End Sub
 
Upvote 0
Thank you Fluff.
its working and is smaller in coding.

Now i wanted to put a command button above column O which when clicked can sort that column O by increasing value (corresponding to other column cells) and when i again click on it, it sort it by decreasing value -vice versa.
Rows are again variable.

thanks and regards,
Abhisekh


This works on the activesheet & replaces both codes you supplied
Code:
Sub FillPlate()
   
   Dim strFormulas(1 To 5) As Variant
   
   strFormulas(1) = "=(H3+ABS(J3))"
   strFormulas(2) = "=(I3+ABS(J3))"
   strFormulas(3) = "=(H3+ABS(J3^2/I3))"
   strFormulas(4) = "=(I3+ABS(J3^2/H3))"
   strFormulas(5) = "=IF(AND(K3>0,L3>0),K3,IF(AND(K3<0,L3<0),0,IF(AND(K3<0,L3>0),0,M3)))"

   With Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
      
   Range("k3:O" & Range("J" & Rows.Count).End(xlUp).Row).Formula = strFormulas


End Sub
 
Upvote 0
To do the sort, try recording a macro which can then be cleaned up a bit.
 
Upvote 0
Hey Fluff,
i recorded macro and came up with below code.

Hey Fluff,
I am able to sort the values by using below code.
I am sure it can be made more compact and better.
I also used a command button on that worksheet which calls Macro 1 to do sorting.But i am not able to make that sorting to in descending order by clicking on same command button.
i think it can be done by modification in code.

thanks and regards,.
Abhisekh

Code:
Sub MySortMacro1()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A3:AD" & LastRow).Sort Key1:=Range("o3:o" & LastRow), _
       Order1:=xlAscending, Header:=xlNo
End Sub
Sub MySortMacro2()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A3:AD" & LastRow).Sort Key1:=Range("T3:T" & LastRow), _
       Order1:=xlAscending, Header:=xlNo
End Sub
Sub MySortMacro3()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A3:AD" & LastRow).Sort Key1:=Range("Y3:Y" & LastRow), _
       Order1:=xlAscending, Header:=xlNo
End Sub
Sub MySortMacro4()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A3:AD" & LastRow).Sort Key1:=Range("AD3:AD" & LastRow), _
       Order1:=xlAscending, Header:=xlNo
End Sub



To do the sort, try recording a macro which can then be cleaned up a bit.
 
Upvote 0
If the button is on the same sheet as the data & its a form control button, try
Code:
Sub MySortMacro1()
   Dim LastRow As Long
   Dim Ord As Long
   Ord = 1
   If ActiveSheet.Buttons(Application.Caller).Caption = "Descending" Then
      Ord = 2
      ActiveSheet.Buttons(Application.Caller).Caption = "Ascending"
   Else
      ActiveSheet.Buttons(Application.Caller).Caption = "Descending"
   End If
   LastRow = Cells(Rows.Count, 1).End(xlUp).Row
   Range("A3:AD" & LastRow).Sort Key1:=Range("o3:o" & LastRow), _
      Order1:=Ord, header:=xlNo
End Sub
 
Upvote 0
Solution
Thank you Fluff,
Its working.
In post #4 you replied the code that copy formula, is there any way that it copies only values calculated from that formula.
may that will be more harder or have to use do while loop.
Thanks for the help.
regards,
Abhisekh

If the button is on the same sheet as the data & its a form control button, try
Code:
Sub MySortMacro1()
   Dim LastRow As Long
   Dim Ord As Long
   Ord = 1
   If ActiveSheet.Buttons(Application.Caller).Caption = "Descending" Then
      Ord = 2
      ActiveSheet.Buttons(Application.Caller).Caption = "Ascending"
   Else
      ActiveSheet.Buttons(Application.Caller).Caption = "Descending"
   End If
   LastRow = Cells(Rows.Count, 1).End(xlUp).Row
   Range("A3:AD" & LastRow).Sort Key1:=Range("o3:o" & LastRow), _
      Order1:=Ord, header:=xlNo
End Sub
 
Upvote 0
Change the last line of the code in post#4 to
Code:
With Range("K3:O" & Range("J" & Rows.Count).End(xlUp).Row)
   .Formula = strFormulas
   .Value = .Value
End With
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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