Consulting

Results 1 to 6 of 6

Thread: Need help deciphering code

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Need help deciphering code

    I inherited an Excel file and it's macros. Before I make any updates, I'm trying to figure out exactly what the macros are currently doing. Can someone help me understand what is happening in the following section of code? It looks like the macro is taking a look at the values in columns 9 and 10 (which are either dates or nothing), so why does it say if "-"?

    [vba]If (col = 11) Then
    If OutArray(row, col - 2) = "-" Or OutArray(row, col - 1) = "-" Then
    OutArray(row, col) = OutArray(row, col - 2) + 30
    ElseIf (Int(DateDiff("d", OutArray(row, col - 2), OutArray(row, col - 1))) > 31) Then
    OutArray(row, col) = OutArray(row, col - 1) + 2
    Else
    OutArray(row, col) = OutArray(row, col - 2) + 30
    End If
    End If
    [/vba]

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    It is looking at an array not at the worksheet, so you need to look at how that array gets populated. I think it uses row and col variables just to think of that array in similar terms as a range.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    Ok, I understand that part... but why does it use "-" in the If statement. What does "-" mean? There are not dashes in the cells.

  4. #4
    But the code is looking at the contents an array not the contents of a cell on the worksheet.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Quote Originally Posted by clhare
    Ok, I understand that part... but why does it use "-" in the If statement. What does "-" mean? There are not dashes in the cells.
    Read what I said, and then ask a question.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    The macro is actually taking information in the spreadsheet and putting it into a new spreadsheet (any only using certain columns from the original). The values in columns 9 and 10 of the original spreadsheet are dates. So it looks to me like the macro checks the contents of the array (which is the contents of the cells in the original spreadhseet). Since the original spreadsheet has no "-" in either column, I'm assuming then that it's not a literal reference. I just don't know what kind of reference it is. At first I thought it might refer to a hyphen in the dates (as in 01-14-2009), but the dates in the column actually use a "/" rather than a "-".

    So I'm kind of lost on this one.

Posting Permissions

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