VBA to replace text of cell in one tab with text of cell in another tab (with condition)

LoverBoA

New Member
Joined
Mar 28, 2015
Messages
6
Hi all, looking to write a code to make my work simpler. Basically there are two tabs I work with, one is the master tab ("Master" tab) and the other tab ("Updated" tab) with updated data each month.

Hope anyone can advise on the code to fulfil the below purpose:-

1. Find, in column A (starting from cell A2 to the last cell A that is Non-Blank) of the "Updated" tab, using the text in cell B2 of the "Master" tab;
2. If the Find is successful at row X of the column A ("Updated" tab), replace cells D2, E2, F2 of the "Master" tab with values of the matched row X (in "Updated" tab), cells KX, LX, MX respectively;
3. If the Find is not successful, skip error.
4. Repeat step 1 for next cell B3 of the "Master" tab;
5. End process when the macro reaches the last cell of column B having text i.e. the next cell B is blank.

The macro needs to run fast for a few thousand iterations hence would appreciate any advice on improving my above logic as well!

Thanks for any advice!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this code...

Code:
Sub FindAndUpdate()
Dim shM As Worksheet
Dim shU As Worksheet
Dim rData As Range
Dim rC As Range
Dim rF As Range
    Set shM = Sheets("Master")
    Set shU = Sheets("Updated")
    Set rData = shM.Range(shM.Cells(2, "B"), shM.Cells(Rows.Count, "B").End(xlUp))
    Application.ScreenUpdating = False
    For Each rC In rData.Cells
        Set rF = shU.Columns("A:A").Find(What:=rC.Value, LookAt:=xlWhole, _
            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
        If Not rF Is Nothing Then
            rC.Offset(0, 2).Value = rF.Offset(0, 10).Value
            rC.Offset(0, 3).Value = rF.Offset(0, 11).Value
            rC.Offset(0, 4).Value = rF.Offset(0, 12).Value
        End If
    Next rC
    Application.ScreenUpdating = True
    MsgBox "Data processing completed.", vbInformation
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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