+ Reply to Thread
Results 1 to 14 of 14

Random Rooms

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Random Rooms

    Hello

    I am stock. Help.

    I added a columns for dates and when I click the button it stop working the button for reset.

    My original worksheet was in Sheet2 and the vba code was working for it.
    I left the original code but I don't know which one that I need to change so that it will work for the random in column for Room which B8:E35 which used to be A8:C35.

    Thank you in advance

    See attachment.

    Sub pick_Random()
    
    Sheets("Random Matrix").Unprotect "RD"    '<----- Change as required
    
    Dim i&, j&, k&, rng, rd(1 To 10000, 1 To 1)
    Dim cell As Range
    For Each cell In Range("I8:I20") ' change to actual range of random numbers
        If Not IsEmpty(cell) Then
            k = k + 1
            rd(k, 1) = cell.Value
        End If
    Next
    rng = Range("A8:C35").Value
    Randomize
    For i = 1 To UBound(rng)
        For j = 1 To 3
            If j <> 2 Then rng(i, j) = rd(Int(Rnd * k) + 1, 1)
        Next
    Next
    Range("A8:C35").Value = rng
    
    'add this for the allow users of this worksheet to: Format cells and Sort
    With Sheets("Random Matrix") 'change it here
        .Protect _
            Password:="RD", _
            DrawingObjects:=True, _
            Contents:=True, _
            Scenarios:=True, _
            AllowFormattingCells:=True, _
            AllowSorting:=True
        .EnableSelection = xlUnlockedCells
    End With
    
    Range("B1").Select
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Random Rooms

    It should randomize from B8:B35 and E8:E35

    Thank you

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Random Rooms

    Using the MACRO RECORDER :

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        Range("B8:B35").Select
        ActiveWindow.SmallScroll Down:=-15
        Range("A7:C35").Select
        Application.CutCopyMode = False
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Add Key:=Range( _
            "A8"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Random Matrix").Sort
            .SetRange Range("A7:C35")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        ActiveWindow.SmallScroll Down:=3
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Add Key:=Range( _
            "A8"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Random Matrix").Sort
            .SetRange Range("A7:C35")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Add Key:=Range( _
            "B9:B35"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Random Matrix").Sort
            .SetRange Range("A7:C35")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        ActiveWindow.SmallScroll Down:=0
    
    Macro2
    
    End Sub
    
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Range("D8:F35").Select
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Random Matrix").Sort.SortFields.Add Key:=Range( _
            "E8:E35"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Random Matrix").Sort
            .SetRange Range("D8:F35")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A1").Select
    End Sub
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Random Rooms

    Hi sorry.... I have to closed this forum.

    I have sent a wrong worksheet.

    Thank you

  5. #5
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Random Rooms

    Thank you Logit but I have to unsubscribed with this forum.

  6. #6
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Random Rooms

    Hello

    I wanted Sheet1 to work like Sheet2.
    I created Sheet1 which I added columns for dates. My range for randomized is in B8:B35 and E8:E35. But when I transferred or copied the code from Module1 to Module2 Then I did not work.

    Can you please modify the code in Module2. See attachment worksheet.

    Thank you
    Attached Files Attached Files

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Randomized Room

    Use this:

    PHP Code: 
    Sub pick_Random1()
    Dim k&, rd(1 To 100001 To 1)
    Dim cell As Range
    For Each cell In Range("K8:K" Cells(Rows.Count"K").End(xlUp).Row' from K8 to last used cell in col K
        If Not IsEmpty(cell) Then
            k = k + 1
            rd(k, 1) = cell.Value
        End If
    Next
    Randomize
    For Each cell In Range("B8:E35")
        If cell.Column = 2 Or cell.Column = 5 Then
            cell.Value = rd(Int(Rnd * k + 1), 1)
        End If
    Next
    Range("B1").Select
    End Sub 
    Attached Files Attached Files
    Quang PT

  8. #8
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Randomized Room

    Hi
    Ok.. Thank you bebo.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,587

    Re: Random Rooms

    In future, should you need a thread moving to a different sub-forum, ask a Mod or Admin to do it for you. Please do not open duplicate threads under ANY circumstances. Thank you.

    I have merged the two threads here.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  10. #10
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Random Rooms

    Bebo
    Good morning

    Can you please modify and place the range K8:K to Sheet3 A1:A?

    Thanks

  11. #11
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Random Rooms

    I wanted to type all the room number in Sheet3 A1:A because its easier.

    thank you

  12. #12
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Random Rooms

    May be:

    PHP Code: 
    For Each cell In sheets("Sheet3").Range("A1:A" sheets("Sheet3").Cells(Rows.Count"A").End(xlUp).Row

  13. #13
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,736

    Re: Random Rooms

    Great! Thank you so much

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,587

    Re: Random Rooms

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Address location of rooms
    By marjovdn in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 08-10-2022, 11:09 PM
  2. [SOLVED] Formula to alternate two values between rooms
    By Ricker090 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-11-2017, 06:11 PM
  3. [SOLVED] Are there excel chat rooms
    By Wally Steadman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-20-2016, 04:50 PM
  4. Choosing Rooms
    By realvirtuality1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-18-2014, 05:20 PM
  5. [SOLVED] Search for free rooms
    By Berna11 in forum Excel General
    Replies: 4
    Last Post: 02-16-2014, 05:33 AM
  6. Percentage Formula for rooms completed
    By tf4string in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-19-2013, 07:38 PM
  7. [SOLVED] rooms checklist
    By hany elkader in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-25-2006, 01:15 AM

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