Consulting

Results 1 to 14 of 14

Thread: Sort A to G and S columns

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location

    Sort A to G and S columns

    [vba]r = Range("c65536").End(xlUp).Row
    Range("a5:G" & r).Select

    Selection.Sort Key1:=Range("G5"), Order1:=xlAscending, Key2:=Range("F5") _
    , Order2:=xlAscending, Key3:=Range("C5"), Order3:=xlAscending, Header:= _
    xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
    xlSortNormal
    Rows("4:" & r).Select
    For i = 5 To r
    Rows(i).Select
    If i Mod 2 = 0 Then
    Selection.Interior.ColorIndex = xlNone
    Else
    Selection.Interior.ColorIndex = 36
    End If
    Next
    Range("j5").Select
    Application.Calculation = xlCalculationAutomatic[/vba]

    this sorts range from A to G and set color to each second row how can I include S column in this range
    I mean that cells in column S are moved with cells from columns A to G
    Any help would be apreciated
    thnx
    Last edited by saban; 06-25-2006 at 02:05 PM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Saban,
    Move Column S adjacent to Column G and include it in the sort; move it back on completion.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Hey saban,

    Try switching the range to this:

    [vba]Dim r As Long
    Dim rng As String
    Dim rngS As String

    r = Range("c65536").End(xlUp).Row
    rng = Range("a5:G" & r).Address
    rngS = Range("S5:S" & r).Address

    Range(rng & "," & rngS).Select[/vba]
    Worked for me to include the S column to be selected
    ...didn't test it with the sort, though...




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Joseph,
    You can't sort on multiple selections, so you need to move the data to be sorted.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    thnx guys will let you know how it worked

  6. #6
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by mdmackillop
    Hi Joseph,
    You can't sort on multiple selections, so you need to move the data to be sorted.
    Regards
    MD
    That's beat.

    Well thanks MD. Now I know




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  7. #7
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    Guys if i insert new column excel will change all the formulas coresponding to this column right?
    So I dont have to rewrite all the formulas
    Am I right
    thnx

  8. #8
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    If your formula is C1 = "=B1" and you insert a column before column B (shifting everything from B to the right) then that formula will be in D1 = "=C1"

    Does that answer your question?


    And just try it out, anyway. If it doesn't work, just undo it or use the Replace function (if the formula isn't too complex) to get the formula you need.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  9. #9
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Peace of mind is found in some of the strangest places.

  10. #10
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    So actually it does amend the formula as needed from inserted column to the right ??

    I have another question how to find the bigest value in column H (integer value)

    Thnx

  11. #11
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Type this in whatever cell you want:
    =Large(H:H,1)




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  12. #12
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    But how can I write this with VBA

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Saban,
    Have a look at Formula in the VB help file.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by saban
    Guys if i insert new column excel will change all the formulas coresponding to this column right?
    So I dont have to rewrite all the formulas
    Am I right
    thnx
    Formulae should adapt as required, but if you return the column to its original location then this is not an issue in any case.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •