Link to home
Start Free TrialLog in
Avatar of BBlu
BBluFlag for United States of America

asked on

Excel VBA: using variables in Range object

Is there a way in the attached code to replace the a1 style cell reference for the range object with variables?
Sub AddOneSum()
Dim n As Integer
Dim RanngeToAdd As Range
Dim RangeSum As Integer
Dim LowerRange As String
Dim UpperRange As String
n = 1
LowerRange = "e1"
UpperRange = "e22"
RangeSum = 0
Set RangeToAdd = ActiveSheet.Range("e1:e11")
For Each Cell In RangeToAdd
Cell.Value = n
n = n + 1
RangeSum = RangeSum + Cell.Value
Next
Range("g12").Value = RangeSum
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dynamic range:
=OFFSET($A$1,0,0,COUNT($A:$A),1)
Avatar of BBlu

ASKER

Perfect!  I tried something similar, but thought I had to include the quotes.  Thanks.