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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Text Problem

Status
Not open for further replies.

amal1973

Technical User
Jul 31, 2001
131
US
I have this problem.. I am running a VBA Code on An Excel Sheet , What it does is
It looks for Names that start with known String like ( American –land Or American –state )in Column B . If it finds it. It cuts the whole Row to a different sheet. The cods run perfect. My problem is I want to make the code understands that I would like the to cut all the words that start with “ American” and all the text after the “-“ dash.
This is part the code


Set rngdestination = Worksheets("sheet1").Range("A1")
For i = Cells(Rows.Count, "B").End(xlUp).Row To 1 Step -1


If Cells(i, "B").Value = "American -* " then ------this is the problem
Cells(i, "B").EntireRow.Copy Destination:=rngdestination
Set rngdestination = rngdestination.Offset(rngdestination.Rows.Count)
Cells(i, "B").EntireRow.Delete
End If


Please help
 
I'm thinking that it's reading the string literally and looking for an asterisk (ignoring the wildcard notation of that character)

how about if InStr([start, ]string1, string2)>0 then condition else some other stuff

where string2 is "American -" and string1 is you cell ref.

 
An alternative approach:

If CStr(Cells(i, 2).Value) Like "American -*" Then

ilses
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top