ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Syntax for variable search (https://www.excelbanter.com/excel-programming/273702-re-syntax-variable-search.html)

brym

Syntax for variable search
 
I've narrowed it down with this change:

Dim a, b, c As String

a = "("
b = "?????"
c = ")"
FindWhat = a & b & c

...and changed the line:

Pos = InStr(ActiveCell.Value, a)

But then I'll have to know how many digits in the number beforehand.



Tom Ogilvy

Syntax for variable search
 
See my suggestion.

Regards,
Tom Ogilvy

"brym" wrote in message
...
I've narrowed it down with this change:

Dim a, b, c As String

a = "("
b = "?????"
c = ")"
FindWhat = a & b & c

..and changed the line:

Pos = InStr(ActiveCell.Value, a)

But then I'll have to know how many digits in the number beforehand.





Dick Kusleika

Syntax for variable search
 
brym

Try this sub

Sub FindPar()

Dim FndRng As Range
Dim FirstAdd As String
Dim StartPos As Long
Dim EndPos As Long
Dim i As Long
Dim AllNumbers As Boolean
Const WhatStart As String = "("
Const WhatEnd As String = ")"

Set FndRng = Cells.Find(WhatStart, , , xlPart)

If Not FndRng Is Nothing Then
FirstAdd = FndRng.Address
Do
StartPos = InStr(1, FndRng.Value, WhatStart)
EndPos = InStr(StartPos, FndRng.Value, WhatEnd)
If EndPos 0 Then
AllNumbers = True
For i = StartPos + 1 To EndPos - 1
If Not IsNumeric(Mid(FndRng.Value, i, 1)) Then
AllNumbers = False
Exit For
End If
Next i

If AllNumbers Then
FndRng.Characters(StartPos, EndPos - StartPos + 1).Font.Bold
= True
End If
End If
Set FndRng = Cells.FindNext(FndRng)
Loop Until FndRng.Address = FirstAdd
End If

End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"brym" wrote in message
...
I've narrowed it down with this change:

Dim a, b, c As String

a = "("
b = "?????"
c = ")"
FindWhat = a & b & c

..and changed the line:

Pos = InStr(ActiveCell.Value, a)

But then I'll have to know how many digits in the number beforehand.






All times are GMT +1. The time now is 12:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com