Hi,
I'm looking for a way to clean string in VBA.
What I want to do:
1) search if string contains number in format 3123456/001 where numbers after "3" are random, and 8th character is "/" - in wildcard this looks like that 3######/0## (already done and working)
2) if string contains desired number to remove from string anything but this number
So I am stuck at cleaning string. I've wanted to use InStr, but since it disallow using wildcards it is no use for me.
I want to find string position to trim number and delete another data from string.
I've searched the web and come up with this, but it doesn't work, and does not produce any error
My full code:
Code to solve for finding text position in string:
I'm looking for a way to clean string in VBA.
What I want to do:
1) search if string contains number in format 3123456/001 where numbers after "3" are random, and 8th character is "/" - in wildcard this looks like that 3######/0## (already done and working)
2) if string contains desired number to remove from string anything but this number
So I am stuck at cleaning string. I've wanted to use InStr, but since it disallow using wildcards it is no use for me.
I want to find string position to trim number and delete another data from string.
I've searched the web and come up with this, but it doesn't work, and does not produce any error
My full code:
Code:
Sub temat()
Dim MainString As String, i As Integer, DaneTematu As String
'check if string contains number - already working
DaneTematu = Trim(Range("A2").Value)
If DaneTematu Like "*3######/0##*" = False Then MsgBox "Temat nie zawiera numeru szkody"
If DaneTematu Like "*3######/0##*" = True Then MsgBox "Temat zawiera numer szkody"
'this doesn't work
For i = 1 To Len(DaneTematu)
If Mid(DaneTematu, i, 10) Like "*3######/0##*" Then MsgBox i
'End If
Next
'Trim("String") - to use later
End Sub
Code to solve for finding text position in string:
Code:
Sub temat()
Dim MainString As String, i As Integer, DaneTematu As String
DaneTematu = Trim(Range("A2").Value)
For i = 1 To Len(DaneTematu)
If Mid(DaneTematu, i, 10) Like "*3######/0##*" Then MsgBox i
'End If
Next