IsNumeric and dealing with empty strings

clueless1

New Member
Joined
Apr 16, 2013
Messages
17
Hi there,

I am trying to loop through a set of 3 strings, checking that 2 of them match specific text (StrTest1 = "STRING OF TEXT 1" & StrTest2 = "STRING OF TEXT 2") and then checking the characters of the third string, (OrigString). The third string - OrigString must contain:

some strings that are empty/null - ""
some strings that start with a letter and are followed by numerical digits/chars
some strings that don't start with a letter and are followed by numerical digits/chars
some strings that start with a letter but also have letter(s) in the remainder of the string with numerical digits/chars

At the moment I am only checking the right of the string length, minus 1 character, (the first) is numerical, as the first char should be a letter.
The purpose is to be able to eventually check that the string should start with a letter and the remaining digits/chars are numerical

The problem I currently have is that if the string is empty/ "" the code falls over - but for some reason only on the second empty/"" string?

If I try to say: If OrigString = "" Then GoTo catch_error, the error msg is entered into every cell?

Code:
Sub IsNumericTest()
Application.ScreenUpdating = False
Dim rng As Range
Dim cell As Range
Dim OrigString As String
'Dim StrTest1 As String
'Dim StrTest2 As String
'StrTest1 = "STRING OF TEXT 1"
'StrTest2 = "STRING OF TEXT 2"

Set rng = Range("e2:e22")

    For Each cell In rng
        OrigString = UCase(cell.Value)
        'If OrigString = "" Then GoTo catch_error
        
        If IsNumeric(Right(OrigString, Len(OrigString) - 1)) = False Then
        cell.Offset(0, -3).Value = "Not numeric"
        
        End If
        
'catch_error:
    'cell.Offset(0, -3).Value = "OrigString is blank/empty"
    Next cell
    
Application.ScreenUpdating = True
End Sub

As always, extremely grateful for any help anyone can give and I hope I have explained myself properly.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
The way to solve this is to spot the error at the very earliest point. Don't bother even reading the value to a variable if it is blank.

Code:
For Each cell In rng
    If cell.Value <> "" Then
        OrigString = UCase(cell.Value)
        ...
       ...
    End If
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,665
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top