Looking for an advanced find and replace

Lavster

New Member
Joined
Sep 8, 2014
Messages
1
Hi I wondered if someone can give me an idea. I've got lots of vb programming experience but not much vba

basically I have a list of values

then I want to have another sheet with the list with that list on column a and what I want to replace it with in b

so example
sheet 1 a1 = 9999
then find 9999 in sheet 2 in Column a125 but replace the sheet 1 value with b125
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Well it won't replace the value in A1, but a simple VLOOKUP will return the value in B125. For instance:

=VLOOKUP(A1,Sheet2!$A$1:$B$999,2,0)

Not sure if this helps...
 
Upvote 0
Lavster,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


Sample raw data worksheets:


Excel 2007
AB
1111111
2222222
3333333
4999999
5
Sheet2



Excel 2007
A
19999
23333
32222
41111
5
Sheet1


After the macro in worksheet Sheet1:


Excel 2007
A
199
233
322
411
5
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub Find_Replace()
' hiker95, 09/08/2014, ME804146
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, f As Range
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w1
  For Each c In .Range("A1", .Range("A" & Rows.Count).End(xlUp))
    Set f = w2.Columns(1).Find(c.Value, LookAt:=xlWhole)
    If Not f Is Nothing Then
      c = w2.Cells(f.Row, 2).Value
      Set f = Nothing
    End If
  Next c
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the Find_Replace macro.
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top