I have a For Each loop running on the Worksheet_Change event. The loop runs through each cell in the target range, and picks out those cells that actually have changed. Once it finds a cell, I want it to add it to a global variable range.
Consider the code:
Running this code gives me a "Run-time error '5': Invalid procedure call or argument" when it tries:Code:Dim lastTarget(0 To 50) As String Dim changedCells as Range Private Sub Worksheet_Change(ByVal Target As Range) Dim cell As Range Dim j As Integer For Each cell In Target 'Check to see if the cell actually changed If lastTarget(j) <> cell.Value Then 'Add changed cell to a list Set changedCells = Union(changedCells, cell) End If j = j + 1 Next cell End SubI'm assuming it's giving me an error because of the Union() call, but I'm passing 2 ranges as it expects. I would just pass the cell.Address to a string array, but I need the changedCells to be a range so I can use it in an Intersect() later. Anyone able to help?Code:'Add changed cell to a list Set changedCells = Union(changedCells, cell)
***This problem has been solved, "Both parameters for Union() must NOT be Nothing."
***New issue: removing a cell from a range, see below.




Reply With Quote