+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Thread: Find and replace

  1. #1
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Find and replace

    I am a novice in excel so please bare with me.

    I was wondering if it is possible to do this unique find and replace that is explained below.

    I have many columns with data from our database. I have one column that has my html layout in it. I want to find within the html text data and replace it with data from another column for that row.

    Example: We have [[manufacturer]] in the html area that we want to replace with data from our column called Manufacturer. So, it will replace the text in the html named [[Manufacturer]] with that rows Manufacturer data we have.

    Is that possible to do?
    Last edited by lnjsports; 06-10-2009 at 11:07 AM.

  2. #2
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    5,953

    re: Find and replace

    Hi Injsports,

    I'd recommend uploading a copy of your workbook (minus any sensitive data) so we can take a look. In the workbook be sure to have an example (or a few) of what your data looks like now, and how you want it to look afterward.

    Thanks!

  3. #3
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    re: Find and replace

    Thank for replying to my post to see if this is possible.

    I attached a two row sample of my data. My full workbook is very large with over 10,000 items with a lot more columns then what is showing. I just deleted a lot of the columns that are not really associated with what my request is about.

    If you look at the column (C) Template, you will see the sample template html that I provided. In the html, you will see text with [[ ]] around text. That is the text that I would like to replace with data from the associated column. ( [[PRODUCT_NAME]] with PRODUCT_NAME data ) I want to do this for each [[ ]] in the template html.

    Does this make sense?
    Attached Files Attached Files

  4. #4
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,770

    re: Find and replace

    Maybe like this:
    Sub x()
        Dim s       As String
        Dim cell    As Range
    
        s = "[[" & Range("E1").Text & "]]"
    
        For Each cell In Range("C2", Cells(Rows.Count, "C").End(xlUp))
            cell.Replace What:=s, Replacement:=Cells(cell.Row, "E").Text, _
                         LookAt:=xlPart, MatchCase:=True
        Next cell
    End Sub
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,780

    Re: Find and replace

    ="<table width=""100&#37;"" border=""1"" cellspacing=""12"" cellpadding=""4"">
      <tr> 
        <td colspan=""2"" align=""center""><p>[["&A2&"]]</p>
          <p>[["&B2&"]]</p></td>
      </tr>
      <tr> 
        <td width=""450"" align=""center"">[["&L2&"]]</td>
        <td width=""56%"" align=""left"" valign=""top""><p>Manufacturer: [["&E2&"]] 
          </p>
          <p>Description:<br>
            [["&D2&"]]</p>
          <p>Size: [["&G2&"]]</p>
          </td>
      </tr>
      <tr> 
        <td colspan=""2"" align=""center""><p>- Huge Blow Out Sale -<br>
            Suggested Retail Price: [["&F2&"]]</p>
          <p>&quot;BUY IT NOW FOR&quot;<br>
            [["&I2&"]]<br>
          </p></td>
      </tr>
    </table>"
    sort of works but its nor easy to see.
    youd be better of using mail merge with word using excel as your source to do this.
    word is far better for this html editing than excel
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find and replace

    Thank you SHG for that information. Please remember what I stated at the start of the topic. I am an novice here. I know that for many if not all other members here, they totally understood what that code means and does, but, I just said, WOW!

    How would I go about in performing the code you just suggested.

  7. #7
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find and replace

    Mail Merge? Never used it.

  8. #8
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,780

    Re: Find and replace

    well if you using office you should really look into using word and mailmerge, part of the same toolbox really!!!!!!!
    essentially put template in word , make all those bits in [[ ]] merge fields and it would pull the data from excel
    creating a nice page of html from each row in excel
    Last edited by martindwilson; 06-09-2009 at 08:40 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  9. #9
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find and replace

    Thank you MartinD,

    I just tested out the Mail Merge which it did do what I wanted for giving me the HTML with all fields filled in. BUT, how do I associate each new html with that row on my excel file?

    Basically I want to have the template column or even a new column with the new html in it because then I have to use some of the columns not shown with the new html in an upload.

  10. #10
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,780

    Re: Find and replace

    ah ! i was assuming you just needed to generate the html and would use the word doc for upload.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  11. #11
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find and replace

    That mail merge did do the trick of what I wanted but then I would have over 10,000 of this html in word that I would have to manually put back into my excel file.

    So, since that will not work, are there any other possible ways?

  12. #12
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,780

    Re: Find and replace

    trouble is its so large you cant see whats in it because the formula bar view goes over it!
    but ive had a look and if you put function i posted earlier in template cell and drag down it should work
    the attached word doc shows whats cell c2(page1) and c3 (page2) after puting function in c2 and dragging down
    Attached Files Attached Files
    Last edited by martindwilson; 06-09-2009 at 10:17 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  13. #13
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find and replace

    WOO HOO!

    I finally figured out to use the code that SHG gave me above to make it work.

    With the code that he supplied, do I need to set up a newly edit module for every find and replace I do? Or is there a code that would do all of them?

  14. #14
    Registered User
    Join Date
    05-30-2009
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find and replace

    Hey SHG,

    That code really worked great for the sample you gave me. I then tried editing the code to do another column but it came up with an error. I was doing the [[Description]] text with the column (D) Description. The column has some html style text in it. I am not sure if that matters.

    This is the code I edited for that one:
    Sub x()
        Dim s       As String
        Dim cell    As Range
    
        s = "[[" & Range("D1").Text & "]]"
    
        For Each cell In Range("C2", Cells(Rows.Count, "C").End(xlUp))
            cell.Replace What:=s, Replacement:=Cells(cell.Row, "D").Text, _
                         LookAt:=xlPart, MatchCase:=True
        Next cell
    End Sub

  15. #15
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,770

    Re: Find and replace

    Post the workbook that doesn't work.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

+ 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.2.0