PDA

View Full Version : Need help deciphering code



clhare
01-14-2009, 05:45 AM
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 "-"?

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

Thanks!

xld
01-14-2009, 06:56 AM
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.

clhare
01-14-2009, 07:24 AM
Ok, I understand that part... but why does it use "-" in the If statement. What does "-" mean? There are not dashes in the cells.

KevinTHFC
01-14-2009, 09:22 AM
But the code is looking at the contents an array not the contents of a cell on the worksheet.

xld
01-14-2009, 09:28 AM
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.

clhare
01-14-2009, 09:32 AM
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.