Hi
It's a long time since I have used VBA and I am very rusty, please can someone help as I think I'm going round the bend.
I have a spreadsheet that has two sections where the user inputs data that should then add up to 100%. I want a message pop up box to appear if each section does not add up to 100% when they try to close the spreadsheet.
For example the user will input a percentage into cells O4, R4, U4, X4, AA4, AD4, AG4 then there is a sum calculation in AH4 that adds up the cells. If it is 100% great, if not then they need to look at the input area and amend the details. There is a second input area that again the user inputs data into a range and then cell AX4 adds up the cells in that section. So AH4 and AX4 should add up to 100% each before you close the spreadsheet.
I have written the below VBA but it is bringing up the message box to say that AH4 and AX4 are not 100% when currently they are.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Check to see if cell AH4 or AX4 is 100%
If Sheets("LA_Returns").Range("AH4").Value <> 1 Or Sheets("LA_Returns").Range("AX4").Value <> 1 Then
'If either cell is not 100%, cancel the close and tell user with the message below
Cancel = True
MsgBox "Error! In order to close, cells AH4 and AX4 must show 100%. Please check the input fields"
'If both cells equals 100%, save and close
Else
ThisWorkbook.Close SaveChanges:=True
'End the If and the sub procedure
End If
End Sub
I have checked the code itself on vba checker and there were no issues found. But I am stuck and think I must have missed something obvious along the way. Please can anyone assist?
Any help at all would be appreciated, thank you
Bookmarks