Microsoft Office Forums

Microsoft Office Forums (https://www.msofficeforums.com/)
-   Excel (https://www.msofficeforums.com/excel/)
-   -   Search and replace/insert HTML code into Master File using tags (https://www.msofficeforums.com/excel/19887-search-replace-insert-html-code-into-master.html)

dave8555 02-23-2014 04:09 AM

Search and replace/insert HTML code into Master File using tags
 
1 Attachment(s)
Hello

I need ideally a formula that can do the following;


Example of the cell A3 tag 1FINDandREPLACE


Step 1: Look within a specified cell (i.e cell A3) and copy the tag in that cell.
Step 2: Search within cell B2 (B2 contains various text that includes the tags).
The tag in cell B2 is then to be replaced with the content from cell B3.

Step 3: Repeat steps 1 & 2 for tags A3 to A9 and MASTER HTML FILE B1 to L1 and more


This is a simple idea, but unfortunately I have not been able to find the code already in the forums that can do this task?


Attached is the problem in the excel file.


I look forward to your suggested formula, or if a formula is not possible, a macro could be used and any suggestions on the macro code would be helpful.


Kind Regards
David

Pecoflyer 02-23-2014 07:15 AM

Cross post http://www.excelguru.ca/forums/showt...ed=1#post11600

macropod 02-23-2014 03:51 PM

I'd be inclined to use a macro:
Code:

Sub Demo()
Application.ScreenUpdating = False
Dim LRow As Long, LCol As Long, cCol As Long, cRow As Long
Dim StrTmp As String, StrFnd As String, StrRep As String
With ActiveSheet
  LRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
  LCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
  For cCol = 2 To LCol
    StrTmp = .Cells(2, cCol).Value
    For cRow = 3 To LRow
      If Trim(.Cells(cRow, 1).Value) = "" Then Exit For
      StrFnd = .Cells(cRow, 1).Value
      StrRep = .Cells(cRow, cCol).Value
      StrTmp = Replace(StrTmp, StrFnd, StrRep)
    Next
    .Cells(LRow + 2, cCol).Value = StrTmp
  Next
End With
Application.ScreenUpdating = True
End Sub

As coded, the macro outputs the modified data two rows below whatever the current last row is.


All times are GMT -7. The time now is 03:21 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft