Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,658
- Office Version
- 365
- 2016
- Platform
- Windows
I am using the line of code (in blue) below to attempt to sort a dynamic range of cells in row ("drow" starting at Z. Since the range is dynamic, I'm having difficulty figuring out how to define the range to be sorted.
An example,
Drow = 6
Z6 = "Zebra"
AA6 = "Alligator"
Need to sort Z6:AA6, to result in "Alligator" being in Z6 and "Zebra" in AA6
How best to adjust this code to accomplish the desired results?
Rich (BB code):
Sub ExtractNamesToRow(grp As String, grp2 As String, drow As Long)
Dim names() As String
Dim j As Long, i As Long
' Split the string into an array using the comma as a delimiter
names = Split(grp, ",")
'drop the arra values horizontally from column Z
ws_dump.Range("Z" & drow).Resize(1, UBound(names) + 1).Value = Application.Trim(names)
'sort values right from Z
ws_dump.Range(ws_dump.Cells(drow, 26), ????????).Sort Key1:=ws_dump.Range("Z" & drow), Order1:=xlAscending, Orientation:=xlLeftToRight
i = 26
Do While ws_dump.Cells(2, i) <> ""
grp = grp & ", " & ws_dump.Cells(2, i)
i = i + 1
Loop
i = 27
Do While ws_dump.Cells(2, i) <> ""
grp2 = grp2 & ", " & ws_dump.Cells(2, i)
i = i + 1
Loop
End Sub
An example,
Drow = 6
Z6 = "Zebra"
AA6 = "Alligator"
Need to sort Z6:AA6, to result in "Alligator" being in Z6 and "Zebra" in AA6
How best to adjust this code to accomplish the desired results?