+ Reply to Thread
Results 1 to 5 of 5

How to skip values that cause mismatch error

Hybrid View

ethan.wal How to skip values that cause... 08-16-2019, 11:50 AM
CK76 Re: How to skip values that... 08-16-2019, 12:04 PM
Andy Pope Re: How to skip values that... 08-17-2019, 04:34 AM
jindon Re: How to skip values that... 08-17-2019, 05:06 AM
CK76 Re: How to skip values that... 08-17-2019, 10:24 AM
  1. #1
    Registered User
    Join Date
    07-17-2019
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    5

    How to skip values that cause mismatch error

    I have a simple VBA code that functions fine provided there are not any symbols in any of the cells. When there are symbols, I get the mismatch error. I have included "On error resume next" in my loop; however, the previous value is output into a cell instead of leaving it blank. How do I adjust my code so that when there is a symbol in an input cell, the output cell remains blank instead of just having the previous value placed?

    
    Sub test()
    
    Dim num1 As Single, num2 As Single
    
    For i = 1 To 8
    
    On Error Resume Next
    
    num1 = Sheet1.Cells(6 + i, 5)
    num2 = Sheet1.Cells(6 + i, 6)
    
    Sheet1.Cells(6 + i, 8).Value = num1 * num2
    
    
    Next i
    
    
    End Sub

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: How to skip values that cause mismatch error

    You should first check that cell holds numeric value.

    Ex:
    For i = 1 To 8
        If TypeName(Sheet1.Cells(6 + i, 5)) = "String" Or TypeName(Sheet1.Cells(6 + i, 6)) = "String" Then
        Else
            num1 = Sheet1.Cells(6 + i, 5)
            num2 = Sheet1.Cells(6 + i, 6)
            
            Sheet1.Cells(6 + i, 8).Value = num1 * num2
        End If
    Next i
    Alternately you can use Application.Count() for checking.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: How to skip values that cause mismatch error

    @CK76,

    I think you will need to add the .Value property to the test otherwise Range will be returned rather than the typename for the contents.

    TypeName(Sheet1.Cells(6 + i, 5).Value)
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to skip values that cause mismatch error

    Let the formula do the job.
    Sub test()
        Dim i As Long
        i = 1
        With Sheet1.Cells(i + 6, 8).Resize(8)
            .FormulaR1C1 = "=iferror(rc[-3]*rc[-2],0)"
            .Value = .Value
        End With
    End Sub

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: How to skip values that cause mismatch error

    Andy thanks for catching that one forgot to add it

+ 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. Type mismatch error after pasting values
    By jaydog0813 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2018, 11:21 AM
  2. [SOLVED] RunTime Error 13 ( type mismatch ) error is comming TextboxAfter_Update
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2017, 03:55 AM
  3. Type mismatch error when assigning values resulting from a linear interpolation
    By seigna in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2015, 09:01 PM
  4. Type mismatch error- What is the reason behind the error message?
    By Endre111 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2014, 02:03 PM
  5. Complile Error: Type Mismatch ??? After adding error trap
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2012, 03:50 PM
  6. Conditional Formatting - Run Time Error '13' Type Mismatch Error
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2011, 07:37 PM
  7. [SOLVED] Type Mismatch error & subscript out of range error
    By Jeff Wright in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2005, 03:06 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