I want to look for a string "GAS CYLINDERS" in range "B17:B29" and if a cell contains the given string, go to column "H"(from "B") of the same row of the cell which contains the string then, select it.I want it to loop till row 29 and keep on selecting the eligible cells and take the sum of the values of all selected cells and finally , paste the total in another cell ("M22")
Code I tried:
ROW_NUMBER = 16
ROW_NUMBER = ROW_NUMBER + 1
PARTICULARS = Sheets("Invoice").Range("B" & ROW_NUMBER)
XXX = InStr(PARTICULARS, "GAS CYLINDER")
For Each XXX In Range("B17: B29")
If MYRNG = Empty And InStr(PARTICULARS, "GAS CYLINDER") > 1 Then
MYRNG = XXX.Address
ElseIf InStr(PARTICULARS, "GAS CYLINDER") > 1 Then
MYRNG = MYRNG & "," & XXX.Address
End If
Next XXX
Range(MYRNG).Select
Selection.Offset(0, 6).Select
Image for reference
PS: I'm new to VBA. The code that i tried i found on You tube and Google and I modified it a little because the code i initially found didn't get me the expected result.