Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    LOOP (Excel 2000)

    Hi all,
    I'm trying create a loop that will offset a cell, first I would like to select range A2 then store the value of that cell in a variable. I would like it to loop a certain number of times, 10 to be exact, then, but at each interval of the loop add the value of that cell to the variable. I guess the first question I need to ask is whether or not I am using the active cell properly, or should I use the range object?

    Any help would be much appreciated.

    Darryl
    .

    Public Sub try()
    Dim x As Integer
    Dim y As Integer
    Dim z As Integer
    y = 0
    Application.Worksheets(1).Range("A2").Select
    Do Until x > 360
    x = x + 36
    z = ActiveCell.Offset(x, y).Value + ActiveCell.Value
    z = z + z
    Loop
    Worksheets(1).Range("D1").Value = z

    End Sub

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LOOP (Excel 2000)

    I would do it like this:

    <code>
    Option Explicit
    Public Sub Try()
    Dim I As Long, lSum As Long
    lSum = 0
    For I = 0 To 360 Step 36
    lSum = lSum + woorksheets(1).Range("A2").Offset(I, 0).Value
    Next I
    End Sub
    </code>
    Legare Coleman

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: LOOP (Excel 2000)

    Thanks Legare.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •