PDA

View Full Version : find text format



lior03
12-12-2005, 01:57 PM
hello
i got the idea for the following sub from johnske's site
the aim is to find all cells in a selection that contains a
similar text format - like four characters ("????")
or all words that begins with a certain letter ("M*")
Sub likeit2()
Application.ScreenUpdating = False
Dim cell As Range
Dim x As String
x = InputBox("select text format")
For Each cell In Selection
Selection.clearformats
If cell Like x Then
cell.Font.ColorIndex = 3
End If
Next
Selection.Font.Bold = True
Application.ScreenUpdating = True
End Sub
i want to enable the user decide what he wants to search and let him find it through an inputbox.
it do not work.maybe i should not enter data using "" to the inputbox?.
any suggestions guys !!
thanks

austenr
12-12-2005, 02:05 PM
Hi Moshe,

The sub works if you select the range first then run the sub. You need to have a way to select the range, either by the user or in the code.

like this:

Sub GetUserRange()
Dim UserRange As Range

prompt = "Select a cell for the output."
Title = "Select a cell"
' Display the Input Box
On Error Resume Next
Set UserRange = Application.InputBox( _
prompt:=prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection
' Was the Input Box canceled?
If UserRange Is Nothing Then
MsgBox "Canceled."
Else
UserRange.Range("A1") = Output
End If
End Sub