Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Syntax for variable search

Addendum

Dim rng as Range
set rng = Cells.Find(what:="(*)", after:=ActiveCell, LookIn:=xlValues,
LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)


Should work for negative numbers.

Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
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






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Syntax for variable search

Hi Tom!

In my first post I changed the FindWhat to "(*)" and xlWhole. Now it only
hits cells containing (number) and moreover only the first 3 letters
are changed to bold.

And no, it will always be in connection with a text.

In my sheets i could have this in a cell:

this is a sample (12345) cell value

I want only (12345) to be e.g. bold. As mentioned in my later post, I can do
this, IF I know the number of letters I'm searching for (?????). I would
like only the brackets to be the limits.

(Hitting an (abc) is ok. I'll find a solution for that.)

Regards Birger


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Syntax for variable search

Sub PartOfString()
Dim rng As Range
Dim firstAddress As String
Set rng = Cells.Find(what:="(*)", after:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)

If Not rng Is Nothing Then
firstAddress = rng.Address
Do
With rng.Characters(Start:=2, _
Length:=Len(rng) - 2).Font
.Name = "Arial"
.FontStyle = "Bold"
End With
Set rng = Cells.FindNext(rng)
If rng Is Nothing Then Exit Do
Loop While rng.Address < firstAddress
End If
End Sub

Assuming you don't want to work on cells like

this cell has (12345) in it

but only cells like

(12345)

--
Regards,
Tom Ogilvy



"brym" wrote in message
...
Hi Tom!

In my first post I changed the FindWhat to "(*)" and xlWhole. Now it only
hits cells containing (number) and moreover only the first 3 letters
are changed to bold.

And no, it will always be in connection with a text.

In my sheets i could have this in a cell:

this is a sample (12345) cell value

I want only (12345) to be e.g. bold. As mentioned in my later post, I can

do
this, IF I know the number of letters I'm searching for (?????). I would
like only the brackets to be the limits.

(Hitting an (abc) is ok. I'll find a solution for that.)

Regards Birger




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a range of rows based on a variable; syntax error Babymech Excel Discussion (Misc queries) 3 January 16th 09 06:19 PM
macro syntax for selecting variable range Matt Excel Discussion (Misc queries) 1 October 31st 07 07:13 PM
VBA Syntax for using a variable in a worksheet function xjetjockey Excel Discussion (Misc queries) 3 January 9th 07 04:23 AM
Syntax for variable search brym Excel Programming 2 August 6th 03 05:32 PM
Syntax for variable search Don Guillett[_4_] Excel Programming 0 August 6th 03 04:35 PM


All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"