Type mismatch error when no values added
Results 1 to 3 of 3

Thread: Type mismatch error when no values added
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Mar 2018
    Posts
    30
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Type mismatch error when no values added

    Hello again

    I have the code below working that someone wrote for me. It works great, but when a textbox on the multipage is blank I get a Type mismatch error. I've tried writing an error check and everything, but I just keep getting errors. Does anyone know how to make it so that when the text box is blank it just adds the textboxes that do have numbers?

    Code:
    Private Sub cbEnterFees_Click()
       
    'Enters UserForm data onto spreadsheet
        Dim ans As Long
        Dim i As Long
      
                     
        i = 0
        For Each Control In MultiPage1.Pages(i).Controls 'For each control on Multipage1
            If TypeName(Control) = "TextBox" Then ans = ans + Control.Value 'the answer is the answer plus the value in the textbox
            Next
        ActiveCell.Offset(0, 2).Value = ans
        Unload FeesForm
    
    
     
    End Sub

  2. #2
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Type mismatch error when no values added

    Quote Originally Posted by mykulpasskwa View Post
    Hello again

    I have the code below working that someone wrote for me. It works great, but when a textbox on the multipage is blank I get a Type mismatch error. I've tried writing an error check and everything, but I just keep getting errors. Does anyone know how to make it so that when the text box is blank it just adds the textboxes that do have numbers?

    Code:
    Private Sub cbEnterFees_Click()
       
    'Enters UserForm data onto spreadsheet
        Dim ans As Long
        Dim i As Long
      
                     
        i = 0
        For Each Control In MultiPage1.Pages(i).Controls 'For each control on Multipage1
            If TypeName(Control) = "TextBox" Then ans = ans + Control.Value 'the answer is the answer plus the value in the textbox
            Next
        ActiveCell.Offset(0, 2).Value = ans
        Unload FeesForm
    
    
     
    End Sub
    Code:
    Private Sub cbEnterFees_Click()
    'Enters UserForm data onto spreadsheet
        Dim ans As Long
        Dim i As Long
        i = 0
        For Each Control In MultiPage1.Pages(i).Controls 'For each control on Multipage1
            If TypeName(Control) = "TextBox" Then
                If Control.Value <> "" Then
                    ans = ans + Val(Control.Value) 'the answer is the answer plus the value in the textbox
                End If
            Next
        ActiveCell.Offset(0, 2).Value = ans
        Unload FeesForm
    End Sub
    That will validate it for you.

  3. #3
    New Member
    Join Date
    Mar 2018
    Posts
    30
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Type mismatch error when no values added

    I love this community. Thanks! I added another End If after the first End If cause I was getting a For without Next error, but otherwise that worked PERFECTLY. Thanks again.

    Code:
    Private Sub cbEnterFees_Click()
    'Enters UserForm data onto spreadsheet
     'Modified  5/21/2019  9:02:00 PM  EDT
        Dim ans As Long
        Dim i As Long
        i = 0
        For Each Control In MultiPage1.Pages(i).Controls 'For each control on Multipage1
            If TypeName(Control) = "TextBox" Then
                If Control.Value <> "" Then
                    ans = ans + Val(Control.Value) 'the answer is the answer plus the value in the textbox
                End If
                End If
            Next
        ActiveCell.Offset(0, 2).Value = ans
        Unload FeesForm
    
    
     
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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