I am trying to scroll through each row of a range and copying row to a new range that match a certain criteria.
If each row matches the union works correctly. If there is a row that does not match the criteria then then next row that does match does not get joined by the union command -- even though the correct path through the code is followed.
Can I emphasise - the code follows the correct path, there is no error message but rngTemp does not increase in size -- the extra row is not added. Make all rows in rngSource fit the criteria and then the Union works as expected.
Can anyone explain?
If each row matches the union works correctly. If there is a row that does not match the criteria then then next row that does match does not get joined by the union command -- even though the correct path through the code is followed.
Can I emphasise - the code follows the correct path, there is no error message but rngTemp does not increase in size -- the extra row is not added. Make all rows in rngSource fit the criteria and then the Union works as expected.
Can anyone explain?
Code:
For Each wbSource In Workbooks
If wbSource.Name <> "PERSONAL.XLSB" Then
If Not wbSource.Name = wbTarget.Name Then
Set wsSource = wbSource.Worksheets("Risk Log")
Set rngSource = wsSource.UsedRange
For Each rngRow In rngSource.Rows
If Left(rngRow.Cells(1, 2), 3) = "TS:" Then
If Not rngTemp Is Nothing Then
Set rngTemp = Union(rngTemp, rngRow) ' this is the problem row
Else
Set rngTemp = rngRow
End If 'temp range is empty
End If 'a TS row
Next 'row
End If 'target worksheet
End If 'personal.xlsb