Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Union of Ranges Failed

Public Sub Workbook_Open()
' This Sub checks each Sheet (1-4), calculates the data range for
each, and
' then adds then all to a total Data Range (data ranges declared
Global
' as WeekOne, WeekTwo, WeekThree, WeekFour and WeekAll)
' Function Call CHKROW Just checks if the cell range is Blank to let
me know
' I have reached the end of the data lines on that sheet.

Dim AddRange As Range
Dim ChkSheet As Worksheet
Dim DataLine As Long
For Each Sh In ThisWorkbook.Worksheets
If Sh.Name < "Totals" Then
DataLine = 0
Worksheets(Sh.Name).Activate
Set AddRange = Sheets(Sh.Name).Range(Cells(1, 1), Cells(1,
10))
Do
DataLine = DataLine + 1
Set AddRange = Union(AddRange,
Sheets(Sh.Name).Range(Cells(DataLine, 1), Cells(DataLine, 10)))
If ChkRow(DataLine) = Blank Then Exit Do
Loop
Select Case ActiveSheet.Index
Case 1
Set WeekOne = AddRange
Case 2
Set WeekTwo = AddRange
Case 3
Set WeekThree = AddRange
Case 4
Set WeekFour = AddRange
End Select
Else
Set WeekAll = Union(WeekOne, WeekTwo, WeekThree, WeekFour)

End If
Next
End Sub

This all works as I wanted it to, until It gets to "Set WeekAll =
Union(WeekOne, WeekTwo, WeekThree, WeekFour)" It give me an error
setting the range of the global variable. (all the rest worked just
fine) Any one know why?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Union of Ranges Failed

You can't union ranges on separate sheets.

--
Regards,
Tom Ogilvy

"Barry Wright" wrote in message
...
Public Sub Workbook_Open()
' This Sub checks each Sheet (1-4), calculates the data range for
each, and
' then adds then all to a total Data Range (data ranges declared
Global
' as WeekOne, WeekTwo, WeekThree, WeekFour and WeekAll)
' Function Call CHKROW Just checks if the cell range is Blank to let
me know
' I have reached the end of the data lines on that sheet.

Dim AddRange As Range
Dim ChkSheet As Worksheet
Dim DataLine As Long
For Each Sh In ThisWorkbook.Worksheets
If Sh.Name < "Totals" Then
DataLine = 0
Worksheets(Sh.Name).Activate
Set AddRange = Sheets(Sh.Name).Range(Cells(1, 1), Cells(1,
10))
Do
DataLine = DataLine + 1
Set AddRange = Union(AddRange,
Sheets(Sh.Name).Range(Cells(DataLine, 1), Cells(DataLine, 10)))
If ChkRow(DataLine) = Blank Then Exit Do
Loop
Select Case ActiveSheet.Index
Case 1
Set WeekOne = AddRange
Case 2
Set WeekTwo = AddRange
Case 3
Set WeekThree = AddRange
Case 4
Set WeekFour = AddRange
End Select
Else
Set WeekAll = Union(WeekOne, WeekTwo, WeekThree, WeekFour)

End If
Next
End Sub

This all works as I wanted it to, until It gets to "Set WeekAll =
Union(WeekOne, WeekTwo, WeekThree, WeekFour)" It give me an error
setting the range of the global variable. (all the rest worked just
fine) Any one know why?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
printing Union of Ranges anny Excel Worksheet Functions 2 January 26th 06 10:22 AM
union method for non-adjacent ranges Dana DeLouis[_5_] Excel Programming 0 September 16th 03 03:29 PM
union method for non-adjacent ranges Tom Ogilvy Excel Programming 0 September 16th 03 02:21 PM
union method for non-adjacent ranges Jim Rech Excel Programming 0 September 16th 03 02:17 PM
VBA union of two ranges s[_2_] Excel Programming 1 August 21st 03 02:18 AM


All times are GMT +1. The time now is 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"