#1
|
|||
|
|||
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 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 |
#2
|
||||
|
||||
Where did you get this code? Evidently it's not your own.
RE: TopRow = (DayRange * 16) + 14 This code simply takes whatever the current DayRange value is (1 to 365), multiplies it by 16 then adds 14.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Try:
Code:
Sub SortDaysProvider2() Application.ScreenUpdating = False With ActiveWorkbook.Worksheets("DATABNY").Sort For DayRange = 1 To 365 TopRow = (DayRange * 16) + 14 sRange = "B" & TopRow & ":" & "O" & TopRow + 15 fRange = "B" & TopRow & ":" & "B" & TopRow + 15 .SortFields.Clear '**************************** .SortFields.Add Key:=Range(fRange), SortOn:=xlSortOnValues, _ Order:=xlAscending, DataOption:=xlSortNormal .SetRange Range(sRange) .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply Next DayRange End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Will VBA code work in a web browser? | PeligrosoBlanco | PowerPoint | 1 | 03-28-2012 11:57 PM |
work vs regular work. and how regular work works | user0044 | Project | 5 | 03-06-2012 07:28 AM |
My Product code doesnt work!!!! PLEASE HELP | dukquaknoobhack | Office | 1 | 01-05-2012 03:43 PM |
How can I make this work? | only300 | Office | 1 | 10-20-2011 02:52 AM |
simple code doesn't work help | piper7971 | PowerPoint | 2 | 08-19-2010 08:15 AM |