VBA integer message box amendment

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

Joe4 recently very kindly provided this code for me:

VBA Code:
Dim A As Integer
Dim ttl As String

A = Sheets("Address Tracking").Range("M25").Value Mod 1000
ttl = Format(Application.WorksheetFunction.RoundUp(Sheets("Address Tracking").Range("M25"), -3), "#,##0") & " Miles from Current Home Address Countdown"

'Event 1
If 1000 - A <= 17 Then MsgBox 1000 - A & " miles to go until you reach " & Format(Sheets("Address Tracking").Range("M25").Value + 1000 - A, "#,##0") & " miles", vbInformation, ttl

'Event 2
If A > 0 And A <= 10 Then MsgBox "Congratulations! You have now run over " & Format(Sheets("Address Tracking").Range("M25").Value + 1000 - A, "#,##0") & " miles from this address", vbInformation, "Another 1,000 Miles Run From This Address"

I've been trying to amend this code so that it triggers a message box on each of the above 2 events i.e.

Event 1: When the value of A is greater than 28,489 and less than 28,506 and then greater than 29,489 and less than 29,506 and then greater than 30,489 and less than 30,506 and so on i.e. every increase in value being 1,000.

Event 2: When the value of A is greater than 28,504 and less than 28,516 and then greater than 29,504 and less than 29,516 and then greater than 30,504 and less than 30,516 so on - again, every increase in value being 1,000

I'm having problems getting the right format and so I'd be grateful for the solution.

Many thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Resolved
VBA Code:
'Event 1 (This Workbook_Open)
Dim E As Integer
Dim title4 As String
E = Sheets("Address Tracking").Range("M25").Value Mod 1000
title4 = Format(Sheets("Address Tracking").Range("M25").Value + 1000 - E, "#,##0") & " Miles Approaching From This Home Address"

If 1000 - E <= 15 Then MsgBox "You've almost reached " & Format(Sheets("Address Tracking").Range("M25").Value + 1000 - E, "#,##0") & " miles run from this home address!", vbInformation, title4

VBA Code:
'Event 2 (WorkSheet_Change Event)
Dim C As Integer
C = Range("MilesFromHomeAddress").Value Mod 1000

If C > 0 And C <= 10 Then MsgBox "Congratulations! You have now run over " & Format(Range("MilesFromHomeAddress").Value - C, "#,##0") & " miles from this home address", vbInformation, "1,000 More Miles Run"
 
Upvote 0
Solution

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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