Hi Could someone please help understand this loop. As i need this code for a joining a range of cells that have some empty cells.
Thanks great web site i have attached a workbook
Sub a()
Dim LR As Long, cell As Range, rng As Range, cells As Range
Dim newrange As Range
Dim counter As Variant
For Each cell In Sheet3.Range("ServiceDates")
If cell.Value <> "" Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next cell
rng.Select
End Sub
'The first time through loop first cell checked and contains data. if statement = true
' The first time through loop rng is empty. if statment = true
' rng is set to first cell range.
'Second time through loop rng is still set to first cells rng and through out the rest of the loop iterations remains set to first cells range.
'The union method is joing the first cells range to the rest of the other cells ranges.
This this correct cheers
Bookmarks