+ Reply to Thread
Results 1 to 3 of 3

USERFORM/Textbox, Error 13, when TextBox is empty

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2021
    Location
    Canada
    MS-Off Ver
    2019
    Posts
    2

    Question USERFORM/Textbox, Error 13, when TextBox is empty

    Hello, Ive been loosing my mind trying to understand how to complete this macro based on a USERFORM.
    The first If statement seems to work as planned.

    Problem arises when I try to insure that the value a user inputs to the USERFORM/TextBox falls within Sheets(“BinConversion”).Range(“a” & I)
    Anything outside of these numbers ">0 and <13" would MsgBox user to correct.

    One of the secondary issues I can't seem to beat is if I backspace the TextBox to empty I get a Error 13 Mismatch (Debug: x = Bin1Input.Value
    It's my limited understanding that the variable is a double and therefor an empty space is being read as a string, hence the mismatch.

    Lastly, The looping is flawed as depending on how Ive tried to write the code. It either skips the first If Statement, or goes into death loop and I must restart Excel to stop the sub.


    Private Sub Bin1Input_Change()
    
    Dim x As Double
    Dim I As Double
    
    x = Bin1Input.Value
    
    For I = 4 To 28
    If x = Sheets(“BinConversion”).Range(“a” & I) Then
    Sheets(“QLDailySheet”).Range(“b6”) = Sheets(“BinConversion”.Range(“b” & I)
    
    ElseIf x = IsEmpty Then
    MsgBox “Please Enter A Measurement Between 1 and 13 Meters”, vbExclamation
    End If
    Next
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: USERFORM/Textbox, Error 13, when TextBox is empty

    Check if the textbox is empty before doing anything else.
    Private Sub Bin1Input_Change()
    Dim x As Double
    Dim I As Long
    
        If Bin1Input.Value = "" Then
            MsgBox “Please Enter A Measurement”, vbExclamation
            Exit Sub
        End If
    
        x = Bin1Input.Value
    
        For I = 4 To 28
            If x = Sheets(“BinConversion”).Range(“a” & I) Then
                Sheets(“QLDailySheet”).Range(“b6”) = Sheets(“BinConversion”.Range(“b” & I)
    
            ElseIf x = IsEmpty Then
                MsgBox “Please Enter A Measurement Between 1 and 13 Meters”, vbExclamation
            End If
        Next I
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-26-2021
    Location
    Canada
    MS-Off Ver
    2019
    Posts
    2

    Re: USERFORM/Textbox, Error 13, when TextBox is empty

    ...........
    Last edited by StreetSweeper1; 02-28-2021 at 10:16 AM.

+ 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. [SOLVED] From ComboBox to TextBox - Set default value in TextBox as blank/empty
    By Deniouz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-11-2020, 11:51 AM
  2. [SOLVED] Userform textbox value to cell only if textbox not empty
    By Catsonheat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2019, 09:20 AM
  3. Run-time error ‘13’: Type mismatch on Userform textbox if empty
    By dentler in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2017, 03:37 AM
  4. [SOLVED] userform condition if textbox is empty do nothing
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2016, 08:04 AM
  5. [SOLVED] Checking for empty textbox and setfocus the empty textbox
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-23-2013, 02:49 PM
  6. Message Box if any of userform textbox are empty
    By Rey Ocampo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-16-2012, 02:42 PM
  7. UserForm textbox data to empty cells
    By RLWells in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2012, 02:42 AM

Tags for this Thread

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