Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2012, 05:31 AM
gbaker gbaker is offline Can't make code work. Windows 7 32bit Can't make code work. Office 2010 32bit
Competent Performer
Can't make code work.
 
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, 8 views)
Reply With Quote
  #2  
Old 07-13-2012, 09:58 PM
macropod's Avatar
macropod macropod is offline Can't make code work. Windows 7 64bit Can't make code work. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-13-2012, 10:01 PM
macropod's Avatar
macropod macropod is offline Can't make code work. Windows 7 64bit Can't make code work. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



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
Can't make code work. work vs regular work. and how regular work works user0044 Project 5 03-06-2012 07:28 AM
Can't make code work. My Product code doesnt work!!!! PLEASE HELP dukquaknoobhack Office 1 01-05-2012 03:43 PM
Can't make code work. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft