+ Reply to Thread
Results 1 to 5 of 5

Checking range for a number from userform textbox more than 6 times

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-10-2014
    Location
    Alberta
    MS-Off Ver
    2016
    Posts
    128

    Checking range for a number from userform textbox more than 6 times

    I have a piece of code that I am unaware of. I want the code to check if the Roomnum.Value is already in 6 cells, then a MsgBox will appear. So, for example, if they write the number 30 in the Roomnum textbox and it occurs in the range of "C6:E38" 6 times already, then the msgbox will show. This is the code I have, and it works, but not the way I want to obviously.

    Private Sub Roomnum_AfterUpdate()
        If Roomnum.Value > 6 Then
            MsgBox "This number is shown 6 times already"
            Exit Sub
        End If
    End Sub
    This code works if you input a number over 6 then the msgbox will show. I am not sure how it should be written if the value occurs more than 6 times.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Checking range for a number from userform textbox more than 6 times

    Please re-read your post. I don't see the correlation of the number 30 with anything else (could it 30, 60, 8 million?: It doesn't seem to effect anything). I fear you have made a mistake in your post.

  3. #3
    Forum Contributor
    Join Date
    08-10-2014
    Location
    Alberta
    MS-Off Ver
    2016
    Posts
    128

    Re: Checking range for a number from userform textbox more than 6 times

    stnkynts, 30 was just an example, so yes it could be anything, just as long as it doesn't occur 6 times within the range. Thanks for your help though.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Checking range for a number from userform textbox more than 6 times

    Something like:
    Dim rng As Range
    Set rng = ActiveSheet.Range("C6:E38")
    If WorksheetFunction.CountIf(rng, Roomnum.Value) >= 6 Then
        MsgBox Roomnum.Value & " appears at least 6 times", vbOKOnly + vbInformation, "Excel Forum"
    End If
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  5. #5
    Forum Contributor
    Join Date
    08-10-2014
    Location
    Alberta
    MS-Off Ver
    2016
    Posts
    128

    Re: Checking range for a number from userform textbox more than 6 times

    Thank you Olly. It works perfectly.

+ 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. Error Checking with Range cell in Userform. Thank you!
    By florayaoyao in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2014, 07:23 PM
  2. [SOLVED] Add 1 to the last number in a textbox in a userform
    By skip2mylew in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2014, 07:45 AM
  3. [SOLVED] Problems Making A Userform Textbox Continue To Flash More Than 3 Times
    By LoneWolf3574 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2013, 10:58 PM
  4. [SOLVED] Userform textbox number formats
    By PhilM in forum Excel General
    Replies: 2
    Last Post: 06-07-2006, 06:15 AM
  5. [SOLVED] checking input on a textbox in userform to be a %
    By Jean-Pierre D via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-25-2005, 07:05 PM

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