Hi all,
I have the following code to display a message box if a range doesn't sum to 100%
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.Sum(Range("D6:D9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("E6:E9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("F6:F9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("G6:G9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("H6:H9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("K6:K9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("L6:L9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("M6:M9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("N6:N9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
If Application.WorksheetFunction.Sum(Range("O6:O9")) <> 1 Then
MsgBox "Note: Market shares for year do not sum to 100%, please check entries"
End If
End Sub
However the msgbox appears even if the cells do sum to 100. I have tested all the ranges using the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Application.WorksheetFunction.Sum(Range("D6:D9")) = 1
End Sub
and found that the problem is in the range D6:D9. This range returns true as expected in most cases, but occasionally false even if the numbers sum to 100%.
i.e. 5% 5%
65% 41%
13% 43%
17% sums to 100% and returns true 11% sums to 100% but returns false.
Could anyone provide any ideas as to why this might be happening?
Thanks in advance,
James
Bookmarks