If String Like

dantheman9

Board Regular
Joined
Feb 5, 2011
Messages
175
Hi Im having some issues using the String Like function to compair two strings, coding im trying to get to work is as follows;

HTML:
If TempStr Like "<td  style= ' border-color: #FFFFFF #000000 #000000 #FFFFFF'  align='center' align='center' colspan='7'><big><b>*" Then
Print #1, "</table>"
Print #1, "</div>"
tablenumber = tablenumber + 1
billnum = "<div id=" & Chr(34) & "billboard" & tablenumber & Chr(34) & "class =""billcontent"">"
Print #1, billnum
Print #1, "<table>"
End If

im not 100% sure im using the like function correctly, will the wildcard at the end take acount of all text after including spaces or will i need to ad wildcards for the bits that might change and then add any remiaing text after?
 
Last edited by a moderator:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
The wildcard pattern will match all the text at the end of your string including spaces.

You can use a simple test like this to confirm that and test other patterns.

Code:
Sub TEST_Like()
    Dim s1 As String, sPattern As String
    Dim bResult As Boolean
    
    s1 = "ABC  xyz  123  "
    sPattern = "ABC*"
    
    bResult = s1 Like sPattern
    MsgBox "s1 Like sPattern: " & bResult
End Sub
 
Upvote 0
HTML:
If TempStr Like "<td  style= ' border-color: #FFFFFF #000000 #000000 #FFFFFF'  align='center' align='center' colspan='7'><big><b>*" Then
The main problem I see with the above Like Pattern is the # signs... they are wildcards to the Like operator standing in for a single digit character. I am guessing that is not what they are meant to be in your Like Pattern. If you encase the # signs in square brackets, then Like will see them as simple characters and not wildcards. Try that code line this way and see if it works for you then...

HTML:
If TempStr Like "<td  style= ' border-color: [#]FFFFFF [#]000000 [#]000000 [#]FFFFFF'  align='center' align='center' colspan='7'><big><b>*" Then
I also note you Like Pattern has a couple of double blanks in it... your TempStr variable's content will need to have those same double blanks for the match to occur.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,567
Messages
6,160,541
Members
451,655
Latest member
rugubara

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