+ Reply to Thread
Results 1 to 4 of 4

wildcards in replace

  1. #1

    wildcards in replace

    I am trying to get rid of all cells that contain multiple ='s. For
    instance in A13 it may read ===== === =========== =======. Then
    in A40, it may read = ====== = ====. Basically these lines are
    stopping my trim statements from running. I already have a line that
    deletes all empty rows so it would be realy great if I could just get
    rid of the characters all together and then delete teh row with that
    line.


  2. #2
    Jim Thomlinson
    Guest

    RE: wildcards in replace

    Give this a try...

    Public Sub test()
    Call RemoveDuplicates("=")
    End Sub

    Public Sub RemoveDuplicates(ByVal ReplaceCharacter As String)
    Dim wks As Worksheet
    Dim rngToSearch As Range
    Dim rngFound As Range

    Set wks = Sheets("Sheet1")
    Set rngToSearch = wks.Cells
    Set rngFound = rngToSearch.Find(What:=ReplaceCharacter & _
    ReplaceCharacter, LookAt:=xlPart)

    Do While Not rngFound Is Nothing
    rngToSearch.Replace What:=ReplaceCharacter, _
    Replacement:=""
    Set rngFound = rngToSearch.Find(What:=ReplaceCharacter & _
    ReplaceCharacter, LookAt:=xlPart)
    Loop
    End Sub
    --
    HTH...

    Jim Thomlinson


    "[email protected]" wrote:

    > I am trying to get rid of all cells that contain multiple ='s. For
    > instance in A13 it may read ===== === =========== =======. Then
    > in A40, it may read = ====== = ====. Basically these lines are
    > stopping my trim statements from running. I already have a line that
    > deletes all empty rows so it would be realy great if I could just get
    > rid of the characters all together and then delete teh row with that
    > line.
    >
    >


  3. #3
    Jim Thomlinson
    Guest

    RE: wildcards in replace

    Sorry htat was adapted from some old code that I had that needs a little
    tweaking... Try this...

    Public Sub test()
    Call RemoveDuplicates("=")
    End Sub

    Public Sub RemoveDuplicates(ByVal ReplaceCharacter As String)
    Dim wks As Worksheet
    Dim rngToSearch As Range
    Dim rngFound As Range

    Set wks = Sheets("Sheet1")
    Set rngToSearch = wks.Cells.SpecialCells(xlCellTypeConstants)
    Set rngFound = rngToSearch.Find(What:=ReplaceCharacter, LookAt:=xlPart)

    Do While Not rngFound Is Nothing
    rngToSearch.Replace What:=ReplaceCharacter, _
    Replacement:=""
    Set rngFound = rngToSearch.Find(What:=ReplaceCharacter,
    LookAt:=xlPart)
    Loop
    End Sub

    That gets rid of the ='s. Did you still need some help on the deleting rows?
    --
    HTH...

    Jim Thomlinson


    "Jim Thomlinson" wrote:

    > Give this a try...
    >
    > Public Sub test()
    > Call RemoveDuplicates("=")
    > End Sub
    >
    > Public Sub RemoveDuplicates(ByVal ReplaceCharacter As String)
    > Dim wks As Worksheet
    > Dim rngToSearch As Range
    > Dim rngFound As Range
    >
    > Set wks = Sheets("Sheet1")
    > Set rngToSearch = wks.Cells
    > Set rngFound = rngToSearch.Find(What:=ReplaceCharacter & _
    > ReplaceCharacter, LookAt:=xlPart)
    >
    > Do While Not rngFound Is Nothing
    > rngToSearch.Replace What:=ReplaceCharacter, _
    > Replacement:=""
    > Set rngFound = rngToSearch.Find(What:=ReplaceCharacter & _
    > ReplaceCharacter, LookAt:=xlPart)
    > Loop
    > End Sub
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "[email protected]" wrote:
    >
    > > I am trying to get rid of all cells that contain multiple ='s. For
    > > instance in A13 it may read ===== === =========== =======. Then
    > > in A40, it may read = ====== = ====. Basically these lines are
    > > stopping my trim statements from running. I already have a line that
    > > deletes all empty rows so it would be realy great if I could just get
    > > rid of the characters all together and then delete teh row with that
    > > line.
    > >
    > >


  4. #4

    Re: wildcards in replace

    Your a genius...thanks...worked great.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1