If Selection <> 0 then msgbox

R

Ron

Hello all,
I'm trying to validate that the total of the selected cell is <> 0
but, I'm getting an error with the code below..

Range(Selection, Selection.End(xlDown)).Offset(0, 11).Select
With Selection
If Sum.Selection <> 0 Then
MsgBox "Out of Balance"

End If
End With

Assistance greatly appreciated, Ron
 
R

Ron

Your just missing how to use a worksheet function in VBA:

Range(Selection, Selection.End(xlDown)).Offset(0,
11).Select
With Selection
If Application.WorksheetFunction.Sum(Selection) <> 0 Then
MsgBox "Out of Balance"
End If
End With






--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)

Hi Simon,
Thanks, this will come in handy in other projects. Thank you, Ron
 
R

Ron

Your just missing how to use a worksheet function in VBA:

Range(Selection, Selection.End(xlDown)).Offset(0,
11).Select
With Selection
If Application.WorksheetFunction.Sum(Selection) <> 0 Then
MsgBox "Out of Balance"
End If
End With






--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)

Is there a way to include the difference in the MsgBox?
 
O

Otto Moehrbach

Something like this maybe:
MsgBox "Out of balance. Value is " & ActiveCell.Value & "."
HTH Otto
Your just missing how to use a worksheet function in VBA:

Range(Selection, Selection.End(xlDown)).Offset(0,
11).Select
With Selection
If Application.WorksheetFunction.Sum(Selection) <> 0 Then
MsgBox "Out of Balance"
End If
End With






--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)

Is there a way to include the difference in the MsgBox?
 
R

Ron

Something like this maybe:
MsgBox "Out of balance.  Value is " & ActiveCell.Value & "."






Is there a way to include the difference in the MsgBox?- Hide quoted text-

- Show quoted text -

Hi Otto, since I'm working with a selection of cells could I edit
your solution? If I edit your solution to MsgBox "Out of balance.
Value is " & Selection.Value & "." will this work? Thank you, Ron
 
R

Ron

Ron i think you may need this:

Dim SumRng as long
Range(Selection, Selection.End(xlDown)).Offset(0, 11).Select
With Selection
SumRng= Application.WorksheetFunction.Sum(Selection)
if SumRng <> 0 Then
MsgBox "Out of Balance, range value is " & SumRng
End If
End With

Ron;324548 Wrote:




--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile:http://www.thecodecage.com/forumz/member.php?userid=1
View this thread:http://www.thecodecage.com/forumz/showthread.php?t=90593- Hide quoted text -

- Show quoted text -

Simon, thanks. Exactly what I needed for this situation. Thank you
for your assistance, Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top