I am looping through cells in my WS and want to add the cell address to a range (or array) as the loop finds cells which meet a criteria. I get an Object Requried error at the last line Set
Dim CellArray As Range
With ws
With .Cells(Application.WorksheetFunction.Match("Total checks", .Range("A:A"), 0), Application.WorksheetFunction.Match(ComboBox1.Value,0))
.Formula = "=SUM('" & Root & sourceSheet & ws.Name & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$H:$H)"
Set CellArray = Union(CellArray, This.Address)
try this
please do not use "With" command because it makes code hard to read in most situations (like yours)
Your
CellArray
variable is not initialized. It's thus initiallyNothing
, andUnion
can't takeNothing
as an argument.Also, you can't access the With object (
This
does not exist), so you have to affect the Range to a variable first.The loop body could be written (you have to declare
Dim R As Range
beforehand):