Sorting With Offset(-1) and Left(Range("B", 6) Cannot get it to work properly

Beginner1200

New Member
Joined
Jan 18, 2023
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
My code I have been woorking on

My idea is to get the code. Sort until last row with data, but then go one up and leave the last row alone. And all the rest from A5 until last row -1 with data should be sorting But only to sort the first 6 letters. ex Even if in range("A5:A15") one is ex "105.00" and "185.00; Like" in the range ("A5:A15") It has to sort only the first 6 letters.

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
    9.1 KB · Views: 11

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,886
Messages
6,122,093
Members
449,064
Latest member
Danger_SF

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