Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement comparing strings

Status
Not open for further replies.

jhogie

Technical User
Jun 3, 2008
24
CA
I've been working on this one for a while and quite seem to get it.

I have a sheet ('SheetName') full 'i' number of Tag #s in Column 'A'. The Tag #s are either L-##### or LL-##### (where L/LL are specific combinations of Letters)

I am wanting to enter the 'If Statement' if the Tag #s appear in any of the other sheets ('j' number of sheets)(in B-columns with 'k' number of rows). BUT in the other sheets there may be additional characters appearing after the Tag #. I need to enter the 'If Statment' even if this occurs.

Here is the most recent If statement that I've tried... I just need to figure out what to write after 'Like'.

Code:
If wkb.Worksheets(SheetName).Range("A" & i) Like (Left(wkb.Worksheets(j).Range("B" & k), 8) Or (Left(wkb.Worksheets(j).Range("B" & k), 7))) Then

Any help/suggestions would be greatly appreciated,
Thanks in advance.

-Hogie
 



Hi,

You're close...
Code:
If CStr(wkb.Worksheets(SheetName).Range("A" & i)) Like "'*" & (RIGHT(wkb.Worksheets(j).Range("B" & k), 5) & "*'" Then
I assume that Column A has these 5-digit numbers


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip for the quick reply, but I don't think I explained my issue well enough so your code doesn't fully address work.

However, I actually figured out a different (longer) way of doing it, and it is posted below (for anybody to look at).

Here I am determining the length of the Tag# and then dealing with it as two different casess; weather it has 7 or 8 characters, and just comparing the first 7/8 characters of the tag#s on all the other sheets.

Code:
If Len(wkb.Worksheets(SheetName).Range("A" & i)) = 7 Then
  If wkb.Worksheets(SheetName).Range("A" & i) Like (Left_(wkb.Worksheets(j).Range("B" & k), 7)) Then
    CopyCount = CopyCount + 1
  End If
ElseIf Len(wkb.Worksheets(SheetName).Range("A" & i)) = 8_ Then
  If wkb.Worksheets(SheetName).Range("A" & i) Like (Left_(wkb.Worksheets(j).Range("B" & k), 8)) Then
    CopyCount = CopyCount + 1
  End If
End If

- Thanks again
Hogie
 




The Like operator my be used like...
Code:
If expression1 Like "somevalue[red]*[/red]" then

or

If expression1 Like "[red]*[/red]somevalue" then

or

If expression1 Like "[red]*[/red]somevalue[red]*[/red]" then


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top