Forum Discussion
KewiDK
Dec 19, 2023Copper Contributor
how to validate the last four digits ?
can anybody help me ? I have my code here, but I get no response, if I type etc. 020202-1326 I need to validate the last 4 digits of this string xxxxxx-xxxx with hyphen between 6 and 7 digits. I h...
Rodrigo_
Dec 20, 2023Iron Contributor
KewiDK
Apart from you last line of code, there is also some typos on some line,
- Corrected the variable name: You declared a variable from but used frm in your code. I corrected the declaration to Dim frm As Worksheet
- Removed the CStr function: The CStr function is not necessary when you’re getting the text from a range. So, I removed it and directly assigned the text to strValue.
Here’s the comparison for clarity:
Your code:
Dim from As Worksheet
Set frm = ThisWorkbook.Sheets("Enter data")
Dim strValue As String
strValue = CStr(frm.Range("I6").Text)
...
Than If
here's what I did:
Dim frm As Worksheet
Set frm = ThisWorkbook.Sheets("Enter data")
Dim strValue As String
strValue = frm.Range("I6").Text
...
End If