VBA Sorting

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
Ok, so I have a large set of data that I sort with some code initially and do some other stuff to. Secondly, I have code to insert a break in rows between a range of numbers (this is shown below). Now, that the data is broken up in two portions (an upper, and lower portion), I need to resort the top portion of the data relative to column "V" in ascending order, without touching the top portion. The amount of data changes every week so the ranges are not static, except for the columns, they are always static as I have data A:V. My code to sort the data after the rows are inserted is not working for me because it grabs everything instead of just the top portion of data. Can someone help me adjust this after the rows are inserted.
Code:
Private Sub Insert_Rows() 'Inserts break between 3 & 4 days late
    Dim Found As Range
    Dim counter As Long, sMax As Long
    
    sMax = Application.Max(Range("S:S"))
    counter = 4
    
    Do
    
        Set Found = Range("S:S").Find(counter, Range("S1"), xlValues, xlWhole, xlByRows, xlNext)
        If Not Found Is Nothing Then Found.Resize(4).EntireRow.Insert
        counter = counter + 1
        
    Loop Until Not Found Is Nothing Or counter > sMax
    
    'If Found Is Nothing Then MsgBox "Can't find four or larger."
    
End Sub
Private Sub SecondSort()
    Dim lRow As Long
 
    With Worksheets("detail w add")
        lRow = .UsedRange.Row + .UsedRange.Rows.Count - 1
        .Range("A1", Cells(lRow, "V")).Sort _
                Key1:=.Columns("V"), _
                Order1:=xlDescending, _
                Header:=xlYes
    End With
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I think it may be something like:
Code:
Private Sub SecondSort()
    Dim lRow As Long
 
    With Worksheets("detail w add")
        lRow = .Range("A1").End(xlDown).Row
        .Range("A1", Cells(lRow, "V")).Sort _
                Key1:=.Columns("V"), _
                Order1:=xlDescending, _
                Header:=xlYes
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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