简体   繁体   中英

Find and replace between two worksheets Excel

I would like to be able to automate a find and replace, I have two sheets

The first only has two columns

-----------------------------------------------
| Column 1       | Column 2                   |
-----------------------------------------------
| PO-123-LG      | Polygon base Lime Green    |
| PO-123-PR      | Polygon base Plain Red     |
| PO-123-SY      | Polygon base Sunset Yellow |
| HO-123-LG      | Horice base Lime Green     |
-----------------------------------------------

The second sheet has two columns also

-----------------------------------------------
| Column 1       | Column 2                   |
-----------------------------------------------
| Lime Green     | (Lime-Green)               |
| Plain Red      | (Plain-Red)                |
| Sunset Yellow  | (Sunset-Yellow)            |
-----------------------------------------------

I would like to use the second sheet to find column 1 in the first sheet column 2 and replace it with column 2 on the second sheet so that I now have

-------------------------------------------------------
| Column 1       | Column 2                           |
-------------------------------------------------------
| PO-123-LG      | Polygon base (Lime-Green) etc etc. |
-------------------------------------------------------

Is there any way that I can automate this as I have nearly 50000 rows and doing this manually will be too time consuming.

Any help would be much appreciated.

Sub replacing()

i = 2

Do While (Len(Sheets("B").Cells(i, 2)) > 0)
    Sheets("A").Columns("B:B").Replace What:=Sheets("B").Cells(i, 1), Replacement:=Sheets("B").Cells(i, 2), LookAt:=xlPart, SearchOrder:=xlByRows
    i = i + 1
Loop


End Sub

You need to extract the base name values from Column 2 in Table 1, and then use the value in a VLOOKUP. We can do this easily if all bases contain the word "base" in them.

Here are screenshots showing implementation using Excel formulas:

屏幕截图显示替换

屏幕截图显示了用于替换的公式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM