IIf function in vba works like If function in worksheet.
Returns one of two, IIf(Condition, When true, When false)
Could be rewrite like
So, when loop counter = 1, it returns 1, otherwise 3.
It is used for the row to be pasted in sheet2.
End(xlUp) refers to the last non empty cell, but when the column is blank, it returns 1.
End(xlUp)(1) actually means End(xlUp).Cells(1, 1) (RowRef, ColRef from the cell itself and both optional, 1, 1 is the default).
End(xlUp)(3) will give you 2 rows below after the last non empty cell, so it gives you 1 blank between the data.
One thing you should be very carefull using IIf function is, unlike If in worksheet function, it evaluates both True, False completely.
Therefore you can not used it e.g IIf(Range Is Nothing, Empty, Range.Value), because if Range is Nothing Range.Value is impossible.
HTH.
Bookmarks