Sorting Question - Sort until last cell in range with data (but keep the last cell with data out of the sorting progress) any idea ??

Beginner1200

New Member
Joined
Jan 18, 2023
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
I want to sort the range "B5" order Ascending. But it has to leave the >>100.00; Hull<< out of the sorting progress.
Sorting the whole row with data but it has to leave the last cell in ascending order out of the sorting...
Hope my post gives any sense or meaning and hope anyone can give me hint to get it right :)

Sorting.PNG


VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Range("B5", Range("B5").End(xlUp)).Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlYes
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
How about
VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Range("B4", Range("B" & Rows.count).End(xlUp).Offset(-1)).Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlYes
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Range("B4", Range("B" & Rows.count).End(xlUp).Offset(-1)).Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlYes
End Sub
Hi Fluff

Yes it works! Many thanks :) I first saw your posting today!
An additional question... what is I only want to sort the first 6 numbers ex "300.00" and exclude the all the rest example "300.00; Protection" how do I put this into the coding? Hope you have an idea

:)
 
Upvote 0
Maybe
VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Range("B4:B9").Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlYes
End Sub
 
Upvote 0
I have been working a little with this code here!!
But I cannot get it to work!? I am missing some here????

My piont is it has to sort ex. "185.00; Test" or "325.00; Next" I want in the code only to use "ex 185.00 to sort and to ignore Test... Can this be done with the code issued below??
or do I have to make an different approach?

VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Left(Range("B4"), 6, Left(Range("B"), 6 & Rows.Count).End(xlUp).Offset(-1)).Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlYes
End Sub
 

Attachments

  • Udklip.PNG
    Udklip.PNG
    6.5 KB · Views: 4
Upvote 0
As this is a completely different question, it needs a new thread.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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