+ Reply to Thread
Results 1 to 2 of 2

Find and Replace based on lookup table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-16-2013
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    136

    Find and Replace based on lookup table

    Hi the attached spreadsheet has two tabs one with city's and one that corrects city names based on a lookup table

    I want column A on the data sheet tab to change by looking at the table on the lookup sheet two and replacing the name with values from column B if needed.
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,982

    Re: Find and Replace based on lookup table

    Option Explicit
    
    Sub replaceX()
        Dim s1 As Worksheet, s2 As Worksheet
        Dim i As Long, j As Long
        Dim lr As Long, lr2 As Long
        Set s1 = Sheets("Data_Sheet")
        Set s2 = Sheets("Lookup_Sheet")
        lr = s1.Range("A" & Rows.Count).End(xlUp).Row
        lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
        With s1
            For i = 2 To lr
                For j = 2 To lr2
                    If .Range("A" & i) = s2.Range("A" & j) Then
                        .Range("A" & i) = s2.Range("B" & j)
                    End If
                Next j
            Next i
        End With
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Find and replace by lookup table
    By CB5 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-05-2017, 04:00 PM
  2. [SOLVED] replace cells based on lookup table
    By batchjb69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2014, 03:43 PM
  3. Replies: 16
    Last Post: 11-19-2013, 02:16 AM
  4. Find/replace macro based on lookup.
    By sonoamore in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-23-2013, 03:03 PM
  5. [SOLVED] Lookup Table to Find/Replace Every Instance of a String (2/2)
    By Baghel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2013, 05:49 AM
  6. Replies: 12
    Last Post: 12-31-2012, 04:13 AM
  7. Find and Replace Based on a Table.
    By EggrollZ9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2011, 11:07 AM

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