+ Reply to Thread
Results 1 to 10 of 10

VBA needed to find and replace text using a wildcard

  1. #1
    Registered User
    Join Date
    02-18-2008
    Posts
    23

    VBA needed to find and replace text using a wildcard

    I need to delete a string such as (Being Entered) (Basic Rigging) (Being Entered) (Dogging) from a cell that contains

    RB (Being Entered) (Basic Rigging),DG (Being Entered) (Dogging)

    Currently we dio this manually with the Find & Replace function using wildcards - Replace (*) with nothing thus giving us RB,DG

    Can this be done in a formula so the user does not have to do this manually?
    Last edited by jgupte; 05-29-2012 at 02:38 AM.

  2. #2
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Wildcard Fimd & Replace

    Is the data always the same i.e. numbers of characters in same place? If so this should do it.

    =MID(A1,1,2)&MID(A1,35,3)
    If I helped, please don't forget to add to my reputation. (click on the star below the post)

    If the problem is solved, please: Select Thread Tools (on top of your 1st post) -> Mark this thread as Solved.

    Failure is not falling down but refusing to get up.

  3. #3
    Registered User
    Join Date
    02-18-2008
    Posts
    23

    Re: Wildcard Fimd & Replace

    Unfortunately not. The column has codes for various classes of licences, and in brackets the description of the licence. Most of the time there will be only one licence class in the field (with two strings of characters between brackets), but sometimes there will be two or more licence classes, with three or more strings.

    Here is a sample of the data:

    C2 (Current) (Slewing Mobile Crane (up to 20 tonnes)),DG (Current) (Dogging)
    WP (Being Entered) (Boom Type Elevating Work Platform)
    C6 (Being Entered) (Slewing Mobile Crane (up to 60 tonnes))
    DG (Being Entered) (Dogging),C2 (Being Entered) (Slewing Mobile Crane (up to 20 tonnes))


    As you can see, the first row and last row have the same licence classes, but in a different order.
    This report is generated automatically based on entries made through the web by external customers, so it is not possible to get them to enter the data in the same order.

    Also, some cells could have three or four licence classes.

    What I need is to be able to specify a wild card in the replace function.

    EG

    Replace (CellRef, "(*)", "")

    But this function sees the * as a character and not as a wild card.
    Last edited by jgupte; 05-29-2012 at 01:12 AM.

  4. #4
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Wildcard Fimd & Replace

    I think you need VBA to do this. I recommend that you rename the thread to "VBA needed to find and replace text".

  5. #5
    Registered User
    Join Date
    02-18-2008
    Posts
    23

    Re: Wildcard Find & Replace

    How do I rename the thread?

  6. #6
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Wildcard Fimd & Replace

    To change the title of the thread, click EDIT on the original post, then click the Go Advanced button, then change the title. If two or more days have passed, the EDIT button will not appear, and you need to ask a moderator to change the title.

  7. #7
    Registered User
    Join Date
    04-21-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: VBA needed to find and replace text using a wildcard

    Columns("A:A").Select
    Selection.Replace What:="@*", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

  8. #8
    Registered User
    Join Date
    02-18-2008
    Posts
    23

    Re: VBA needed to find and replace text using a wildcard

    How do I use the above code? (I do not know much about VB).

    Q1: Does the ("A:A") refer to the cell range I want to change?
    Q2: How do I call this routine? Do I put a formula in a cell and refer to this routine as a User Defined function?
    Q3: Does the What:="@*" refer to the test I want to change (eg: change "(*)" to "") ?

    Many thanks.

  9. #9
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: VBA needed to find and replace text using a wildcard

    Jaya Sudha

    Thanks for your response. Do you think you could give the whole of the code so that it can be pasted into the workbook of Jgupte.

  10. #10
    Registered User
    Join Date
    02-18-2008
    Posts
    23

    Re: VBA needed to find and replace text using a wildcard

    Actually I figured it out.

    This code is for a macro.

    I have incorporated it into my full macro and it works well.

    Many thanks.
    Last edited by jgupte; 05-30-2012 at 08:26 PM.

+ 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