checking string for unwanted characters, vba

chris2706

New Member
Joined
Aug 25, 2014
Messages
12
I need to check a string for unwanted characters (only valid HEX characters allowed, 0-9, a-f, A-f)

sub unwantedCHAR()

Dim IPv6_Address As String
IPv6_Address = ThisWorkbook.Names("IPv6_Address").RefersToRange.Value
Dim ipv6_segments() As String
ipv6_segments = Split(IPv6_Address, ":")
ipv6_segments_count = UBound(ipv6_segments) - LBound(ipv6_segments) + 1 If ipv6_segments_count <> 8 Then
MsgBox "The IP address entered for the Westell Remote is not a valid IPv6 address. Expecting 8 segments delimited by a colon (:)", vbCritical + vbOKOnly
Exit Sub
End If

Dim x As Integer
Dim segLEN As Integer


For x = 0 To 7
segLEN = Len(ipv6_segments(x))
If segLEN > 4 Then
MsgBox ("Segment " & (x + 1) & ", " & ipv6_segments(x) & " is not valid IPv6 segment")
End If

<NEED CODE>
check for characters in IPv6_segments(x) that are not valid HEX characters (0-9, a-f, A-F)

I have tried instr and like statements but cannot get it to work properly, any help appreciated

new to Vba
:confused:
 
I used what you supplied as a template, I think I have it working now:

If ipv6_segments(x) Like "*[!0-9A-Fa-f:]*" Then
MsgBox ("prove the negative in segment " & x + 1)
End If
You do not have to loop through the segments, just pass in the entire IPv6 text into my function and it will check everything directly all at once. In other words...
Code:
[table="width: 500"]
[tr]
	[td][COLOR="#008000"]' verify Remote's IPv6 address is valid[/COLOR]
Dim IPv6_Address As String
IPv6_Address = ThisWorkbook.Names("IPv6_Address").RefersToRange.Value
If Not IsIPv6(IPv6_Address) Then
  MsgBox "Your IPv6 address (" & IPv6_Address & ") is invalid!"
  Exit Sub [COLOR="#008000"]'??? Not sure what you want to do here[/COLOR]
End If[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Rick,

Thank you VERY much, you put in the right direction, it is working as expected now, below is the entire code (I adapted what you sent)

so I ended up with this entire code:

Sub segLength()


' verify Remote's IPv6 address is valid
Dim IPv6_Address As String
IPv6_Address = ThisWorkbook.Names("IPv6_Address").RefersToRange.Value
Dim ipv6_segments() As String
Dim ipv6_segments_count As Integer
ipv6_segments = Split(IPv6_Address, ":")
ipv6_segments_count = UBound(ipv6_segments) - LBound(ipv6_segments) + 1
If ipv6_segments_count <> 8 Then
MsgBox "The IP address entered for the Westell Remote is not a valid IPv6 address. Expecting 8 segments delimited by a colon (:smile:", vbCritical + vbOKOnly
Exit Sub
End If

Dim x As Integer
Dim segLEN As Integer


For x = 0 To 7
segLEN = Len(ipv6_segments(x))
If segLEN > 4 Then
MsgBox ("Segment " & (x + 1) & ", " & ipv6_segments(x) & " is not valid IPv6 segment")
End If

If ipv6_segments(x) Like "*[!0-9A-Fa-f:]*" Then
MsgBox ("prove the negative in segment " & x + 1)
End If

Next x

End Sub
 
Upvote 0
Rick,

Thank you VERY much, you put in the right direction, it is working as expected now, below is the entire code (I adapted what you sent)

so I ended up with this entire code:
:confused: The code you posted is not implementing what I posted in Message #11 at all (you are still looping segments).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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