I am trying to filter out the rows having the cells in a particular column (the 'O'th column) with the value "Desired". For this I've written this code
But an error message pops up "Method Union of Object _Global failed" (while setting PTRange in the For Each...Next) loop.
Code:
Set PTRange = ThisWorkbook.Sheets("DumpData").Range("A1:AD1")
Dim frow As Long
frow = ThisWorkbook.Sheets("DumpData").Range("O" & Rows.count).End(xlUp).Row
Set rng = ThisWorkbook.Sheets("DumpData").Range("O2:O" & frow)
Dim count As Long
count = 2
For Each cel In rng
If cel.Value = "Desired" Then
Set PTRange = Union(PTRange, Range("A" & count & ":AD" & count))
count = count + 1
End If
Next cel
But an error message pops up "Method Union of Object _Global failed" (while setting PTRange in the For Each...Next) loop.