![]() |
need help righting script to sort rows alphabetically then seperate them to line up
Hello, can anybody please help me I am new to script righting and was
trying to figure out how to sort my table. I have a table that is at least 800 rows and about 5 columns wide. short example of a row would be ROW column B column C column D column E 1 j1-2 u13-2 j12-4 e3-6 2 e6-34 u12-2 So I found this script (at bottom) that somebody did for somebody else that sorts each row individually alphabetically and it doesn't touch column A which is what I need but every time I have to edit the script with how deep and how wide it is, is there a way so that after you run the script it will prompt you how deep and wide you want it. But also I still need it to seperate each column so no one has more than one starting letter. example after it is sorted it would look like this: ROW column B column C column D column E 1 j1-2 j12-4 e3-6 u13-2 2 e6-34 u12-2 Some have 3 "j's" some have 3 "u's" its somewhat random. is there any way to do this. Right now with the script I found after it alphabatize them. I would then have to sort the columns alphabetically then manually go down the list and shift over the remaining columns to the first column with that letter. then resort and continue this tell there is no column with more then one starting letter (except the first). I would just do it manually except I have to do this a couple times and each one can get around 800-900 rows deep. Thanks in advance for the help. Sub SortRows() Dim r As Long Dim lrow As Long Application.ScreenUpdating = False Application.Calculation = xlCalculationManual lrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row 'Make the r = 3 whatever the first row of data you want to sort on is. 'The Cells(r, 2) means your data starts in Col 2 or Col B - adjust as necessary 'The resize(1, 4) expands the range to 1 cell deep by 4 cells wide For r = 3 To lrow With Cells(r, 2).Resize(1, 4) .Sort Key1:=Cells(r, 1), Order1:=xlAscending, Header:=xlGuess, _ Orientation:=xlLeftToRight, DataOption1:=xlSortNormal End With Next r Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic End Sub |
All times are GMT +1. The time now is 08:17 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com