Transfer value from a cell based on criteria

Podder

New Member
Joined
May 15, 2018
Messages
2
Hi,
i am trying to create a master worksheet that can be updated when another worksheet is uploaded into the same workbook.
what am trying to achieve is that if the text in column A of the uploaded worksheet matches column A of the master worksheet then copy value in column E of that row in the uploaded worksheet and add it to the value of the matching row in column E of the master worksheet using vba.
i am not that familiar with using vba but I am slowly learning
thanks again
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi & welcome to the board.
How about
Code:
Sub MatchAdd()
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   Dim Cl As Range
   
   Set Ws1 = Sheets("[COLOR=#ff0000]Upload[/COLOR]")
   Set Ws2 = Sheets("[COLOR=#ff0000]Master[/COLOR]")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 4).Value
      Next Cl
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then Cl.Offset(, 4).Value = Cl.Offset(, 4).Value + .Item(Cl.Value)
      Next Cl
   End With
End Sub
Change sheet names in red to suit
 
Upvote 0
Hi & welcome to the board.
How about
Code:
Sub MatchAdd()
   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   Dim Cl As Range
   
   Set Ws1 = Sheets("[COLOR=#ff0000]Upload[/COLOR]")
   Set Ws2 = Sheets("[COLOR=#ff0000]Master[/COLOR]")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 4).Value
      Next Cl
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then Cl.Offset(, 4).Value = Cl.Offset(, 4).Value + .Item(Cl.Value)
      Next Cl
   End With
End Sub
Change sheet names in red to suit
Thanks that is what I was after
Also, thanks for the welcome
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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