ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with Union (https://www.excelbanter.com/excel-programming/434242-problem-union.html)

Victor None

Problem with Union
 
When I run this code it only takes the last value in the loop rather 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
http://www.eggheadcafe.com/tutorials...tom-pagin.aspx

p45cal[_138_]

Problem with Union
 

Victor None;505604 Wrote:
When I run this code it only takes the last value in the loop rather
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
Next


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=139031


Gary''s Student

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

--
Gary''s Student - gsnu200905


All times are GMT +1. The time now is 02:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com