Do calculation & show value in Msgbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,736
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I use the code below to transfer values from various cells.
Once the values have been pasted in there new location the last part of the code carries out a calculation.

The calculation looks at the value in cell P35 & compares it with the value of 12570
If the answer is more than 12570 then Currently a Msgbox is shown saying You Are Over £12,570

The above works fine but i now wish to add to this code by telling me how much i am over, also in the same Msgbox

Example.

YOU ARE OVER £12,570 By £3,500





Rich (BB code):
Private Sub JanuaryButton_Click()
If WorksheetFunction.CountA(Range("I9:I18")) = 0 Then
MsgBox "THERE ARE NO VALUES TO TRANSFER", vbCritical, "TRANSFERE RANGE IS EMPTY"

Else

If WorksheetFunction.CountA(Range("E64:E73")) > 0 Then
    answer = MsgBox("CELLS CONTAIN VALUES ALREADY, OVERWRITE THEM ?", vbYesNo + vbCritical, "OVERWRITE CURRENT VALUE MESSAGE")
    If answer = vbNo Then
    Exit Sub
    End If
End If

Range("I9:I18").Copy Destination:=Range("E64:E73")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR

Range("H8").ClearContents
Range("I9:I18").ClearContents
Range("I9").Select
End If

    Set Target = Me.Range("P35")
     
    If Target.Value > 12570 Then

        MsgBox "YOU ARE OVER £12,570", vbExclamation, "PERSONAL ALLOWANCE"
        Exit Sub
    End If

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Like this ?

VBA Code:
.....
      If Target.Value > 12570 Then

        MsgBox "YOU ARE OVER £12,570" & " by " & target.value, vbExclamation, "PERSONAL ALLOWANCE"

       Exit Sub
    End If
.....
 
Upvote 0
To show the formatted difference:

VBA Code:
        MsgBox "YOU ARE OVER £12,570 by £" & Format$(Target.Value - 12570, "#,##0"), vbExclamation, "PERSONAL ALLOWANCE"
 
Upvote 0
Solution
Do you see an issue with why its not adding new line

Rich (BB code):
MsgBox "YOU ARE OVER £12,570 & vbNewLine & vbNewLine & BY £" & Format$(Target.Value - 12570, "#,##0"), vbExclamation, "PERSONAL ALLOWANCE"
 
Upvote 0
You put it inside the quotes so it's literal text, not VBA commands. You need:

VBA Code:
        MsgBox "YOU ARE OVER £12,570" & vbNewLine & vbNewLine & "BY £" & Format$(Target.Value - 12570, "#,##0"), vbExclamation, "PERSONAL ALLOWANCE"
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top