Rearranging rows based on sales and text

SomeGuyHere

New Member
Joined
Aug 24, 2023
Messages
13
Office Version
  1. 2021
Platform
  1. Windows
Hello! I'm trying to use VBA to rearrange rows in the data I have. I want to Make sure all the variations of E and F are grouped together below the highest E or F value. Essentially rearranging rows from the original data in columns A and B to the final arrangement in columns D and E. Is this possible to do? Thank you!
 

Attachments

  • Capture.JPG
    Capture.JPG
    29.5 KB · Views: 9

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Select range in A2:B14

Sort on Item column, that should be enough
 
Upvote 0
Select range in A2:B14

Sort on Item column, that should be enough
Sorry. It wasn't meant to be that easy. :sneaky:
Attached image is the correct scenario of the data I'm working with.
 

Attachments

  • Capture.JPG
    Capture.JPG
    29.3 KB · Views: 6
Upvote 0
how about a formula (Office 365)

Book1
ABCDE
1itemsalesItemSales
2Z100Z100
3X99X99
4Y87Y87
5M81M81
6E80E80
7F64EE53
8EE53EEE22
9FF49EEEE5
10G44F64
11O30FF49
12EEE22FFF15
13FFF15G44
14EEEE5O30
Sheet1
Cell Formulas
RangeFormula
D2:E14D2=LET(z,A2:B14,y,INDEX(z,,1),SORTBY(z,XLOOKUP(LEFT(y),y,INDEX(z,,2)),-1))
Dynamic array formulas.
 
Last edited:
Upvote 0
how about a formula (Office 365)

Book1
ABCDE
1itemsalesItemSales
2Z100Z100
3X99X99
4Y87Y87
5M81M81
6E80E80
7F64EE53
8EE53EEE22
9FF49EEEE5
10G44F64
11O30FF49
12EEE22FFF15
13FFF15G44
14EEEE5O30
Sheet1
Cell Formulas
RangeFormula
D2:E14D2=LET(z,A2:B14,y,INDEX(z,,1),SORTBY(z,XLOOKUP(LEFT(y),y,INDEX(z,,2)),-1))
Dynamic array formulas.
Oh that's amazing. Thanks!

How do I go about expanding that array? My actual data set is much larger than the 14 rows. When I expand the box, it only sorts the original 14 rows. Same with columns. My data is about 5 columns wide and 20 rows down.
 
Upvote 0
This macro puts the output a few cells to the left to show the result. You could also override your existing data

VBA Code:
Sub jec()
 Dim dic, ar, a, j As Long
 ar = Cells(1).CurrentRegion
 Set dic = CreateObject("scripting.dictionary")
 
 For j = 2 To UBound(ar)
   If dic.exists(Left(ar(j, 1), 1)) Then
     a = dic(Left(ar(j, 1), 1))
     a(0) = ar(j, 1)
     a(1) = ar(j, 2)
     dic(ar(j, 1)) = a
   Else
     dic(Left(ar(j, 1), 1)) = Array(ar(j, 1), ar(j, 2), ar(j, 2))
   End If
 Next
   
 With Cells(1, 10).Resize(dic.Count, 3)
   .Value = Application.Index(dic.items, 0, 0)
   .Sort .Cells(1, 3), 2
   .Columns(3).ClearContents
 End With
 
End Sub
 
Upvote 0
This is all based on just one the 2 columns. If you have more columns with items and values, the solutions looks completely different
 
Upvote 0
This is all based on just one the 2 columns. If you have more columns with items and values, the solutions looks completely different
Can xlookup be used to populate the remaining columns? Only the first 2 columns are used as a reference of order. Not sure how to go about doing that, as well as expanding the formula to more rows.
 
Upvote 0
Ok can you give more sample data to make everything clearer?
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,407
Members
449,448
Latest member
Andrew Slatter

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