I am working on a Macro in Excel that needs to iterate through an entire column and find clusters of non-zero data, add up the data and store the result near the mentioned cluster. Then it continues down the column looking for other clusters and doing the same thing.
That being said, I am trying to store a reference to the "target" cell (where the addition of the cluster will be stored) in a variable, and then using that variable to access the "value" property of the cell so that I can make changes to it.
Here's the code:
Sub addNonZeroes()
Dim targetCell
' Select cell E5, *first line of data*.
Range("E5").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
If ActiveCell.Value <> 0 Then
targetCell = ActiveCell.Offset(1, 0)
Do Until ActiveCell.Value = 0
'ERROR OCCURS HERE
targetCell.Value = ActiveCell.Value + targetCell.Value
ActiveCell.Offset(0, 1).Select
Loop
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
End Sub