+ Reply to Thread
Results 1 to 3 of 3

RAND cells but ignore empty cells with data at the top

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    RAND cells but ignore empty cells with data at the top

    I am trying to create a random draw for a golf team event with teams of three, where each team consists of a low - mid - high handicap player. Now I have created the the total number of players under one tab where I sort them into handicap order low to high; then selecting the lowest third I copy and paste them into the low handicap group under tab Random in the sheet below, repeating for the mid and then the high.

    In the Random sheet I have created a macro worksheet where I am trying to do a randomized draw. I have three columns with adjacent RAND columns alongside each. These are columns A - H respectively. There are 23 rows with the heading in row 1. Now after pasting the above entries as above via a button that activates a macro to paste the data into the relevant column.

    Once I have all three columns occupied I then run a macro called RandomDraw which randomizes all three columns. Problem is the data is sorted in all three columns but it sorts the blank cells as well. How can I make ignore the blanks and leave the cells containing data at the top. In this instance I only have 8 names in each column but this could vary.

    The macro that does this is as follows.

    Sub RandomDraw()
    '
    ' RandomDraw Macro
    '
    
    '
        Calculate
        Range("A1:B23").Select
        ActiveWorkbook.Worksheets("Random").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random").Sort.SortFields.Add Key:=Range("B2:B23") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Random").Sort
            .SetRange Range("A1:B23")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("D1:E23").Select
        ActiveWorkbook.Worksheets("Random").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random").Sort.SortFields.Add Key:=Range("E2:E23") _
            , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Random").Sort
            .SetRange Range("D1:E23")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("G1:H23").Select
        ActiveWorkbook.Worksheets("Random").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random").Sort.SortFields.Add Key:=Range("H2:H23") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Random").Sort
            .SetRange Range("G1:H23")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A1").Select
    End Sub
    Sub PasteLow()
    '
    ' PasteLow Macro
    '
    
    '
        Range("A2:A23").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("D2").Select
    End Sub
    Last edited by muffybean; 10-10-2012 at 03:30 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: RAND cells but ignore empty cells with data at the top

    Please edit your post and replace quote with code in each set of brackets.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: RAND cells but ignore empty cells with data at the top

    Sorry about that but I did not realise this. Hope this OK, I am a relative newbie.
    Last edited by muffybean; 10-10-2012 at 03:54 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1