Okay I am quite new to Microsoft VBA and I am trying to apply a code to a personal finance project.
This is my objective:
- If multiple cells exists within a range,
- then fill it with a particular colour and store the numeric values adjacent to it
- print the total value to say another cell say Cells(9,2)
At the moment this is I can only do the 1st object for 1 cell.
Sub Experiment() Dim SrchRng As Range, cel As Range Set SrchRng = Range("A1:A8") For Each cel In SrchRng If cel.Value = Range("A1") Then 'or Cells(row, column) cel.Interior.ColorIndex = 3 End If Next cel For Each cel In SrchRng If cel.Value = Range("A2") Then cel.Interior.ColorIndex = 4 End If Next cel End Sub
When I wanted to do multiple cells like Range("A1, A3, A4") or Range(Cells(x,y), Cells(x,y)), it gave me an error message.