Excel Macro to update sheet values on another sheet where it find a match

Alwinaz

Board Regular
Joined
Feb 7, 2012
Messages
201
Hi

I am using this macro to update two rows on another sheet by finding the matching cell.

Code:
Sub findcode1()
     
    Dim wks As Worksheet
    Dim wks2 As Worksheet
    Dim myR As Range
    
    Set wks = Worksheets("Voorraad")
    Set wks2 = Worksheets("Koop")
    
    If Application.WorksheetFunction.CountIf(wks.Range("A:A"), wks2.Range("a6")) > 0 Then
        ask = wks.Range("A:A").Find(wks2.Range("a6"), wks.Range("A1")).Row
        wks.Range("c" & ask).Value = wks2.Range("g6").Value
       ' wks.Range("O" & ask).Value = wks2.Range("C11").Value
    'End If
    
    If Application.WorksheetFunction.CountIf(wks.Range("A:A"), wks2.Range("a7")) > 0 Then
        ask = wks.Range("A:A").Find(wks2.Range("a7"), wks.Range("A1")).Row
        wks.Range("c" & ask).Value = wks2.Range("g7").Value
       ' wks.Range("O" & ask).Value = wks2.Range("C11").Value
    End If
    End If
    


End sub

Is there a way to update wks will all the matches found in column A on wks2?

Kind regards
Alwina
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
Code:
Sub ReplaceVals()
   Dim Cl As Range
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   
   Set Ws1 = Sheets("Voorraad")
   Set Ws2 = Sheets("Koop")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("A6", Ws2.Range("A" & Rows.count).End(xlUp))
         .Item(Cl.Value) = Cl.Offset(, 6).Value
      Next Cl
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.count).End(xlUp))
         If .exists(Cl.Value) Then Cl.Offset(, 2).Value = .Item(Cl.Value)
      Next Cl
   End With
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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