Hi
I have to track selective blocks of cells in a matrix that is 22 rows deep and
180 columns wide. WHICH blocks I need to track are determined by a drop-down.
Below is a snippet of code I tried using to accomplish this ......
'-----------------
' DataStore
'-----------------
With WS_SByM
Set RngDataStore = .Range("B2").CurrentRegion
Set RngDataStore = RngDataStore.Offset(1, 0).Resize(RngDataStore.Rows.Count - 1)
Set RngDataStore = RngDataStore.Offset(0, 1).Resize(RngDataStore.Rows.Count, RngDataStore.Columns.Count - 1)
'Not Used
DataStoreColCNT = RngDataStore.Columns.Count
End With
'-----------------
' Each Contractor
'-----------------
For c = 1 To ConCNT
StartCol = 1
'-----------------
' 10 Blocks of Months
'-----------------
For iBlock = 1 To 10
Set RngTmp = Nothing
'-----------------
'-----------------
Select Case iBlock
Case 1
Set RngTmp = Range(RngDataStore.Cells(c, StartCol), RngDataStore.Cells(c, NumberOfMonths))
Set oRngUnion = RngTmp
StartCol = StartCol + 18
EndCol = StartCol + (NumberOfMonths - 1)
Case Else
Set RngTmp = Range(RngDataStore.Cells(c, StartCol), RngDataStore.Cells(c, EndCol))
Set oRngUnion = Union(oRngUnion, RngTmp)
StartCol = StartCol + 18
EndCol = StartCol + (NumberOfMonths - 1)
End Select
Next
'-----------------
' THIS FAILS by 2nd pass thru the For loop - no errors
'-----------------
If Not oRngUnionAll Is Nothing Then
Set oRngUnionAll = Union(oRngUnionAll, oRngUnion)
Else
Set oRngUnionAll = oRngUnion
End If
MsgBox "Area Count " & oRngUnionAll.Areas.Count & "Address: " & oRngUnionAll.Address
Pass 1:
=========
?oRngUnion.Address
$C$2:$F$2,$U$2:$X$2,$AM$2:$AP$2,$BE$2:$BH$2,$BW$2:$BZ$2,$CO$2:$CR$2,$DG$2:$DJ$2,$DY$2:$EB$2,$EQ$2:$ET$2,$FI$2:$FL$2
?oRngUnionAll.Address
$C$2:$F$2,$U$2:$X$2,$AM$2:$AP$2,$BE$2:$BH$2,$BW$2:$BZ$2,$CO$2:$CR$2,$DG$2:$DJ$2,$DY$2:$EB$2,$EQ$2:$ET$2,$FI$2:$FL$2
Pass 2:
=========
?oRngUnion.Address
$C$3:$F$3,$U$3:$X$3,$AM$3:$AP$3,$BE$3:$BH$3,$BW$3:$BZ$3,$CO$3:$CR$3,$DG$3:$DJ$3,$DY$3:$EB$3,$EQ$3:$ET$3,$FI$3:$FL$3
?oRngUnionAll.Address
$C$2:$F$3,$U$2:$X$3,$AM$2:$AP$3,$BE$2:$BH$3,$BW$2:$BZ$3,$CO$2:$CR$3,$DG$2:$DJ$3,$DY$2:$EB$3,$EQ$2:$ET$3,$FI$2:$FL$3
In the 2nd pass the ORIGINAL ranges.addresses on oRngUnionAll are there
but the NEW range address related to oRngUnion have not been included.
I assume that Excel CAN DO this but that my approach is incorrect.
Any help is appreciated.
regards
John
Bookmarks