Sum user selections in different colums


Posted by Graham Shaw on February 15, 2001 4:34 AM

My user will be selecting multiple cells (not necessarily adjacent) in 2 different columns that should add to the same value for each column. I need a macro that checks that the total of those selected in the first column equals the value of those selected in the second column. If the totals are OK I then want to copy the values selected to another part of the worksheet.

Any help will be appreciated.

Posted by Dave on February 15, 2001 6:37 AM

Hi Graham

This should do the trick

Sub TryThis()
Dim Sele1 As Range
Dim sele2 As Range

Set Sele1 = Selection.Areas(1)
Set sele2 = Selection.Areas(2)

With WorksheetFunction
If .Sum(Sele1) <> .Sum(sele2) Then
MsgBox "Not equal"
Else
MsgBox "Equal"
End If
End With
End Sub

Dave

OzGrid Business Applications



Posted by Graham Shaw on February 15, 2001 7:39 AM

What service! Thanks.

Graham