Hello guys, I'm a beginner in VBA, I would love it if you can help me out.
Essentially what I would like to do is :
I have two set of datas which have similar variables but one (margin column). I would like to do a macro so that the margin 2 (L column) from the dataset 2 will be stored and then transferred in the dataset 1 (D column). The thing is in the dataset 2, I can have two invoices (or more) for one in the dataset 1. So I would like to sum them up and then send the resultat in the D column next to their invoice number.
I'm stuggling how to integrate the sumIf function in a loop or maybe in a for next.
Here a screen shot of the shrinked dataset (which contains in reality 10 000 rows) :
So far I can only do it manually...I am a bit lost on how to proceed
Thanks for your help
Essentially what I would like to do is :
I have two set of datas which have similar variables but one (margin column). I would like to do a macro so that the margin 2 (L column) from the dataset 2 will be stored and then transferred in the dataset 1 (D column). The thing is in the dataset 2, I can have two invoices (or more) for one in the dataset 1. So I would like to sum them up and then send the resultat in the D column next to their invoice number.
I'm stuggling how to integrate the sumIf function in a loop or maybe in a for next.
Here a screen shot of the shrinked dataset (which contains in reality 10 000 rows) :
So far I can only do it manually...I am a bit lost on how to proceed
VBA Code:
Sub test1()
X As Double
R_row = Range("D3").Row
C_clm = Range("D3").Column
X = Range("J3")
LrJ = Range("J" & Rows.Count).End(xlUp).Row
LrL = Range("J" & Rows.Count).End(xlUp).Row
'variables
Cells(R_row, C_clm) = Application.WorksheetFunction.SumIf(Range("J2:J" & LrJ), X, Range("L2:L" & LrL))
End Sub
Thanks for your help