Hi, thanks for visiting my post.
Basically I have the code already and they do work. But I dun understand the logic behind.
For learning purpose, anyone could teach me why the below works? Codes dun understand have been highlighted
Please assume I am a beginner.
Task: To copy some cells with interior within a specific ranges and I have the code below, which indeed works.
-----
Dim r As Range
.
.
.
For Each cell In Range(Selection, Cells(LastRow, AC))
If cell.Interior.ColorIndex = 6 Then
If r Is Nothing Then <---I do not understand this
Set r = cell <---I do not understand this
Else
Set r = Union(r, cell) <---I do not understand this
End If
End If
Next
If Not r Is Nothing Then r.Copy <---I do not understand this
End Sub
----------------
Thank you v. much
Basically I have the code already and they do work. But I dun understand the logic behind.
For learning purpose, anyone could teach me why the below works? Codes dun understand have been highlighted
Please assume I am a beginner.
Task: To copy some cells with interior within a specific ranges and I have the code below, which indeed works.
-----
Dim r As Range
.
.
.
For Each cell In Range(Selection, Cells(LastRow, AC))
If cell.Interior.ColorIndex = 6 Then
If r Is Nothing Then <---I do not understand this
Set r = cell <---I do not understand this
Else
Set r = Union(r, cell) <---I do not understand this
End If
End If
Next
If Not r Is Nothing Then r.Copy <---I do not understand this
End Sub
----------------
Thank you v. much