WaterSprite
Technical User
[ myArray1 = Worksheets("sheet5").Range("MyTotal_Data_12") ]
How can I use "ActiveSheet" in place of "Sheet5" in the above line of code. I tried doing: DIM Activesheet as Worksheet,
But I still got an error.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim rgMyRange as Range, wsMySheet as worksheet, r as range
Set wsMySheet = Worksheets("sheet5")
Set rgMyRange = wsMySheet.Range("MyTotal_Data_12")
For each r in rgMyRange
with r
debug.print .value, .row, .column, .address
end with
Next
But WHY an array, when you have a collection?
Sub ArraySum2()
Dim myArray1 As Variant, myCount1 As Long, myCount2 As Long
Dim NumRows As Long, NumCols As Long, MyTotals() As Double
myArray1 = Range("MyTotal_Data_12").Value2
NumRows = UBound(myArray1)
NumCols = UBound(myArray1, 2)
ReDim MyTotals(1 To NumRows, 1 To 1)
For myCount1 = 1 To NumRows
For myCount2 = 1 To NumCols
MyTotals(myCount1, 1) = MyTotals(myCount1, 1) + myArray1(myCount1, myCount2)
Next myCount2
Next myCount1
With Range("MyTotalsCol")
.ClearContents
.Resize(NumRows, 1).Name = "MyTotalsCol"
End With
Range("MyTotalsCol").Value2 = MyTotals
End Sub