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

searching for specific characters in a cell

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
oh man i have so many programming problems today lol
basically i have my activecell, i just want to search for a "(" or "-". How would i do that, my thinking is all clouded now, i suppose i run a for loop, where i set my variable to check each character, and if character is "(" or "-" then do this else do that
im just having trouble visualizing how i would do that for cells that have different number of characters in them, should i use the len function so i know how many characters there are in the cell so that i can tell the loop to run that many times, or is there a simpler way to do that until you reach the end of the cell, thanks alot!!
 
Hello again,

If you try this code

pos = InStr(1, "(", ActiveCell.Value, vbTextCompare)

It will return the number of characters in the string the "(" occurs.

You could then do this code

If pos > 0 then
'Do something
Endif


Mike

 
Hi,
Code:
With ActiveCell
   For i = 1 To Len(.Value)
   Select Case Mid(.Value, i, 1)
   Case "("
   ' stuff for this case
   Case "-"
   ' stuff for this case
   Case Else
   ' stuff for every other case
   End Select
   Next
End With
hope this helps :) Skip,
Skip@TheOfficeExperts.com
 
ohh i never thought about it like that, thats pretty cool, and simple thanks alot!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top