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
Range("g12").Value = RangeSum
End Sub

Open in new window

Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:

you mean:
Set RangeToAdd = ActiveSheet.Range(LowerRange & ":" & UpperRange)
Dynamic range:
BBluAuthor Commented:
Perfect!  I tried something similar, but thought I had to include the quotes.  Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.