View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Syntax for variable search

Are the brackets shown because the number is negative - therefore they are
produced by a number format?

If they are not, then the entries are text and can be found with

"(*)"
and lookat:=xlWhole

although this would hit on "(abc)" as well. You would then need to check
if the interior is numeric.

Regards,
Tom Ogilvy


"brym" wrote in message
...
Hi!
This macro I would like to enhance to be more flexible. But before I start
doing (trying) that, I need some help re. the searching syntax.
There's no problem finding a specified part of a string and change the
properties. However, (as I expected) the SQL syntax doesn't work with the
FindWhat var.
Can anyone help me with the syntax so I may find/isolate any number
surrounded by brackets, e.g (98765) or (1234567).

Sub PartOfString()

Dim Pos, Lngt As Integer
Dim FindWhat As String

On Error Resume Next

FindWhat = "Perfect" ' Should be "(" and any whole number and ")"

Cells.Find(what:=FindWhat, after:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

Lngt = Len(FindWhat)
Pos = InStr(ActiveCell.Value, FindWhat)

With ActiveCell.Characters(Start:=Pos, Length:=Lngt).Font
.Name = "Arial"
.FontStyle = "Normal"
End With

End Sub

OR MAYBE - another way to do the trick !?

Thanks in advance

Regards Birger