I'm having trouble with this code. The code goes through one column (column B) and whenever it sees a specific word it would take the value located in column D. e.g if the key word is located in B2 then it would take the value from D2. Below I have coded what I have so far.
Dim MyRange As Range
Dim rcell As Range
Dim i As Integer
Dim Sum_Payment As Double
Set MyRange = Worksheets("Sheet1").Range("B2:B50")
For Each rcell In MyRange.Cells
Debug.Print rcell.Address, rcell.Value
For i = 2 to 50
If rcell.Value = "Payment" Then
Sum_Payment = Sum_Payment + Cells(i, 4).Value
Debug.Print Sum_Payment
ThisWorkbook.Sheets("Sheet2").Activate
ThisWorkbook.Sheets("Sheet2").Range("B2") = Sum_Payment
End If
Next i
Next rcell