Finding cells and updating a row in another sheet

greglowe

New Member
Joined
Feb 27, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello

Trying to set up a sheet to apply a reference to an identical record in another sheet.

on my calc sheet I have:

1645989288329.png


What I need it to do is find the ID on another sheet and update Match on that sheet.

the other sheet is laid out like this:

1645989367481.png


I can get it to work for the first record on the calc sheet but I can figure out how to have it loop through all of the values

It's just updating the same row each time...

the code is have so far is:

VBA Code:
Sub Find_And_Update()

    Dim FindString As String
    Dim Rng As Range
    Dim i As Integer
    Dim MatchRef As String
    
    NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count
    

    FindString = Sheets("Calc Sheet(Agent)").Range("A3")
    
    For x = 1 To NumRows
    
    If Trim(FindString) <> "" Then
        With Sheets("BDX").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
                ActiveCell.Offset(0, 5).Activate
           
           Else
      
            End If
        End With
    End If

    Next x

End Sub

Any help will be greatly appreciated!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
See if this works for you. Just uses VLOOKUP to pull the ID across.

VBA Code:
Sub Find_And_Update()
    Dim refSheet As Worksheet
    Dim calcSheet As Worksheet
    Dim lastRow As Long
    
    Set refSheet = Sheets("Ref") '<-- Change accordingly
    Set calcSheet = Sheets("Calc Sheet(Agent)") '<-- Change accordingly
    
    lastRow = calcSheet.Cells(calcSheet.Rows.Count, 1).End(xlUp).Row
    If lastRow > 1 Then
        With calcSheet.Range("F2:F" & lastRow)
            .Formula = "=IFERROR(VLOOKUP(A2,'" & refSheet.Name & "'!A:B,2,false),"""")"
            .Value = .Value
        End With
        MsgBox "Done :)", vbInformation
    End If
End Sub
 
Upvote 0
HI

Thank you for this!

I should have included this but the match numbers will go up in sequence depending on what's selected...

Is there a way to have the macro ignore anything in the range that already has a value?

Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

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