Ron said:
How does this look?
[....]
SumRng = WorksheetFunction.Round(WorksheetFunction.Sum(Selection), 2)
With WorksheetFunction
SumRng = .Round(.Sum(Selection), 2)
End With
No need to sum and round twice. It doesn't get any better
.
These are just two ways to do the same thing. "With WorksheetFunction"
saves you the trouble of typing "WorksheetFunction" twice in the same
statement. Since you've done it already, I would get rid of the "With
WorksheetFunction" form.
FYI, I see no reason to do "With Selection" in this code snippet.
Of course, if you have more references to Selection objects/methods that you
are not showing here (understandably), that's fine. Otherwise, you might
consider getting rid of the "With Selection".
And it appears that you are missing the statement
Application.ScreenUpdating=True at the end of macro.
Again, the "omission" might be because this code snippet is part of a larger
code, much of which you prudently omitted from your posting so as to focus
on the relevant issues. Just thought I'd bring it to your attention.
One omission seems to be a definite defect, though: you do not have
ActiveSheet.Protect and ScreenUpdating=True statements before the Exit Sub
within the If statement.
----- original message -----
Hi JoeU2004, thanks to you I think I have it working properly. I
really like your approach to the rounding issue and thanks for the
heads up on Rounding. How does this look?
Sub JrnlValidationCode()
Dim mybook As Workbook
Dim ValBook As Workbook
Dim SumRng As Double
Set mybook = ActiveWorkbook
Application.ScreenUpdating = False
ActiveSheet.Unprotect
Range("E12").Select
Range(Selection, Selection.End(xlDown)).Offset(0, 11).Select
With Selection
SumRng = WorksheetFunction.Round(WorksheetFunction.Sum(Selection), 2)
With WorksheetFunction
SumRng = .Round(.Sum(Selection), 2)
End With
If SumRng <> 0# Then
MsgBox prompt:="Out of Balance, Please make the necessary corrections"
_
& vbNewLine & _
"and re-run Validation to complete the validation process." _
& vbNewLine & vbNewLine & _
"Balance should equal ZERO." _
& vbNewLine & vbNewLine & _
"Amount column is out of Balance! " & "$" & SumRng, _
Title:="Amount Column Status"
Exit Sub
End If
End With
'validates columns to meet PeopleSoft requirements.
Range("E12").Select
ValDataI
ValDataK
ValDataN
ValDataW
ValDataAA
ValDataAB
ValDataAI
FindRedCell
Validate
LockCells
ActiveSheet.Protect
End Sub
Although simply rounding the sum might mask this particular abberation,it
would be prudent to use ROUND liberally in most financial calculations in
the Excel spreadsheet as well. That will minimize propagating such
numerical abberations into other spreadsheet calculations. Even formulas
as
innocuous as =A1-A2 can introduce annoying numerical abberations.
----- original message -----
- Show quoted text -- Hide quoted text -
- Show quoted text -