Problem with Union

P

p45cal

Victor said:
When I run this code it only takes the last value in the loop rathe
than giving me the union 1-10. Any help appreciated.

Dim r As Range
Dim rr As Range

For i = 1 To 10
temp = (Cells(i, 1).Value * 1)

Set r = Rows(temp)
Set rr = Application.Union(r, Rows(temp))

Next

rr.Delete



EggHeadCafe - Software Developer Portal of Choice
WPF DataGrid Custom Paging and Sorting
'WPF DataGrid Custom Paging and Sorting' (http://tinyurl.com/y9j43ry)

Try:
For i = 1 To 10
temp = (Cells(i, 1).Value * 1)
Set r = Rows(temp)
Set rr = Application.Union(IIf(rr Is Nothing, Rows(temp), rr)
Rows(temp))
'Debug.Print rr.Address
Nex
 
G

Gary''s Student

If rr Is Nothing Then
Set rr = Rows(temp)
Else
Set rr = Union(rr, Rows(temp))
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top