Consulting

Results 1 to 2 of 2

Thread: find text format

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    find text format

    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*")
    [VBA] 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
    [/VBA] 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
    moshe

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    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:

    [VBA] 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 [/VBA]
    Peace of mind is found in some of the strangest places.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •