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?
As always, extremely grateful for any help anyone can give and I hope I have explained myself properly.
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.