Results 1 to 1 of 1

Thread: Looping through cells in Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    1

    Looping through cells in Excel

    Can someone tell me why this code is wrong?

    Dim Date1 As Range
    Dim Date2 As Range

    Set Date1 = Range("A2")
    Set Date2 = Range("E2")

    Do
    If Date1.Value = Date2.Value Then
    Date2.Offset(0,1).Value = Date2.Offset(0,1).Value + Date1.Offset(0,1).Value
    Set Date1 = Date1.Offset(1,0)

    Else
    Set Date2 = Date2.Offset(1,0)

    Loop Until IsEmpty(Date1)

    I get 'Runtime Error 1004' at the Set Date2 line (the first two dates are not equal) with this code and I'm not sure why. Basically, I have two lists, one of sorted dates (some duplicates, some missing) and a list of all dates for 20 years in order. Each of the first list of dates has a value associated with it, and I need to calculate the sum for all values associated with a given date (thus the duplicates) and put it in the column next to that date in the second list.

    The idea was to compare the first two dates, if they are equal then add the value from the first region to the second, then step to the next date in the first region. If they are unequal, step to the next date in the second region.

    Thanks in advance.

    Edit: Nevermind, I got it--it was searching for something it couldn't find and ran to the end of the spreadsheet. Wish the errors were a bit less cryptic, though.
    Last edited by localtalent; Jul 8th, 2004 at 05:31 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width