I
ilia
I was just running a small macro that processes a datasheet. This is
the code, in the worksheet's module:
With wsh
For iRow = iSourceFirstRow To Me.UsedRange.Rows.Count
Debug.Print iRow
'only process non-zero amounts
If (Me.Cells(iRow, iSourceAnnualAmountCol).Value <> 0)
Then
' process each month's amount
' assumes first month is in column following annual
amount
For iCol = iSourceAnnualAmountCol + 1 To
iSourceAnnualAmountCol + 12
.Cells(iRowDest, iDestLocationCol).Value =
Me.Cells(iRow, iSourceLocationCol).Value
.Cells(iRowDest, iDestDateCol).Value =
Me.Cells(iSourceDateRow, iCol).Value
.Cells(iRowDest, iDestAmountCol).Value =
Round(Me.Cells(iRow, iCol).Value, 2) * 100
.Cells(iRowDest, iDestDescriptionCol).Value = _
Me.Cells(iRow, iSourceFirstName) & " " &
Me.Cells(iRow, iSourceLastName)
iRowDest = iRowDest + 1
Next iCol
End If
Next iRow
End With
I noticed later that I'm missing some of the data, so I did some
debugging - and turned out that UsedRange.Rows.Count was returning one
row less than there actually were in the data sheet! Weird. Turned
out what was causing this was the header row had wrapping turned on,
at least in some cells. As soon as I turned it off, the row count
became normal again.
I'm not sure whether this behavior is known, but it was certainly
unexpected. The only reason I caught it in the first place was
because the resulting spreadsheet is imported into accounting system,
and the debits did not equal the credits so I had to go back and
figure out which numbers went missing and why.
Anyway, thought I'd share - definitely something to look out for.
the code, in the worksheet's module:
With wsh
For iRow = iSourceFirstRow To Me.UsedRange.Rows.Count
Debug.Print iRow
'only process non-zero amounts
If (Me.Cells(iRow, iSourceAnnualAmountCol).Value <> 0)
Then
' process each month's amount
' assumes first month is in column following annual
amount
For iCol = iSourceAnnualAmountCol + 1 To
iSourceAnnualAmountCol + 12
.Cells(iRowDest, iDestLocationCol).Value =
Me.Cells(iRow, iSourceLocationCol).Value
.Cells(iRowDest, iDestDateCol).Value =
Me.Cells(iSourceDateRow, iCol).Value
.Cells(iRowDest, iDestAmountCol).Value =
Round(Me.Cells(iRow, iCol).Value, 2) * 100
.Cells(iRowDest, iDestDescriptionCol).Value = _
Me.Cells(iRow, iSourceFirstName) & " " &
Me.Cells(iRow, iSourceLastName)
iRowDest = iRowDest + 1
Next iCol
End If
Next iRow
End With
I noticed later that I'm missing some of the data, so I did some
debugging - and turned out that UsedRange.Rows.Count was returning one
row less than there actually were in the data sheet! Weird. Turned
out what was causing this was the header row had wrapping turned on,
at least in some cells. As soon as I turned it off, the row count
became normal again.
I'm not sure whether this behavior is known, but it was certainly
unexpected. The only reason I caught it in the first place was
because the resulting spreadsheet is imported into accounting system,
and the debits did not equal the credits so I had to go back and
figure out which numbers went missing and why.
Anyway, thought I'd share - definitely something to look out for.