View Single Post
 
Old 07-13-2012, 05:31 AM
gbaker gbaker is offline Windows 7 32bit Office 2010 32bit
Competent Performer
 
Join Date: May 2012
Posts: 111
gbaker is on a distinguished road
Default Can't make code work.

I need help making this code work.
Trying to sort in groups of 15 lines so that the information goes to the top of each group. See example in workbook attached.
This code is very important because it will complete this project.
Please Help.
Code:
Sub SortDaysProvider2()
Application.ScreenUpdating = False
For DayRange = 1 To 365
    TopRow = (DayRange * 16) + 14
    sRange = "B" & TopRow & ":" & "O" & TopRow + 15
    fRange = "B" & TopRow & ":" & "B" & TopRow + 15
    ActiveWorkbook.Worksheets("DATABNY").Sort.SortFields.Add Key:=
        Range (fRange), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    With ActiveWorkbook.Worksheets("DATABNY").Sort
        .SetRange Range(sRange)
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
Next DayRange
End Sub
I have attached a test sheet to show what I need it to do.
I really don't understand how this code works. Can you explain what TopRow = (DayRange * ) + does
I've tried a number of variations and it still doesn't work.

Thanks in Advance
GWB
Attached Files
File Type: xlsm Test sorting sheet.xlsm (234.4 KB, 10 views)
Reply With Quote