# Message Box when value is within 100 of the next 1000

#### Ironman

##### Well-known Member
Hi

Sheet 'Daily Tracking' Cell CG375 contains a value, currently 27851 and is increasing.

What I'd be really grateful for is a message box that is triggered when I open the workbook if/whenever the value in Sheet 'Daily Tracking' Cell CG375 is within 100 of the next 1000 i.e. it will next trigger between 27900 and 28000. It will then trigger between 28900 and 29000 and so on and in each case it calculates the difference between the two values.

e.g. for 27900 the message would be "100 miles to go until you hit 28,000 miles".

Also, if possible, when the value is equal to or greater than the 1000 by up to 10 e.g. 28000 - 28010 a different message is triggered e.g. "Congratulations, you have now run over 28,000 miles"

I'd also appreciate it if the value could be rounded up to the nearest whole number.

Many thanks!

Last edited:

### Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

#### hrayani

##### Well-known Member
to start with.. try this & let me know if it serves the initial purpose then will try to add other msgbox when the target is over

VBA Code:
``````Private Sub Workbook_Open()

Dim A As Integer

A = Sheets("Daily Tracking").Range("CG375").Value Mod 1000

If 1000 - A <= 100 Then MsgBox 1000 - A & " miles to go until you hit " & Range("CG375").Value + 1000 - A

End Sub``````

#### Ironman

##### Well-known Member
That works fantastic hrayani and made me smile! THANK YOU

#### hrayani

##### Well-known Member
you are welcome

Sounds like you are ok with 1 msg box... don't you need the other msg box which says congrats you have run 10 miles or so over etc etc

#### Ironman

##### Well-known Member
Er no, I was hoping for the other one too please

#### hrayani

##### Well-known Member
Ok
try this

VBA Code:
``````Private Sub Workbook_Open()

Dim A As Integer

A = Sheets("Daily Tracking").Range("CG375").Value Mod 1000

If 1000 - A <= 100 Then MsgBox 1000 - A & " miles to go until you hit " & Range("CG375").Value + 1000 - A
If A > 0 And A <= 10 Then MsgBox "Congratulations! You have now run over " & Range("CG375").Value - A & " miles"

End Sub``````

#### Ironman

##### Well-known Member
Heyyyy that is just brilliant!

Thanks a lot!

#### Ironman

##### Well-known Member
Just a quick one: would it be possible for you to amend your code slightly so there is a thousands separator please? i.e. "xx miles to go until you hit 28,000" (instead of 28000)?

Thanks again!

#### hrayani

##### Well-known Member
Just a quick one: would it be possible for you to amend your code slightly so there is a thousands separator please? i.e. "xx miles to go until you hit 28,000" (instead of 28000)?

Thanks again!
VBA Code:
``````Private Sub Workbook_Open()

Dim A As Integer

A = Sheets("Daily Tracking").Range("CG375").Value Mod 1000

If 1000 - A <= 100 Then MsgBox 1000 - A & " miles to go until you hit " & Format(Range("CG375").Value + 1000 - A, "#,#")
If A > 0 And A <= 10 Then MsgBox "Congratulations! You have now run over " & Format(Range("CG375").Value - A, "#,#") & " miles"

End Sub``````

#### Ironman

##### Well-known Member
VBA Code:
``````Private Sub Workbook_Open()

Dim A As Integer

A = Sheets("Daily Tracking").Range("CG375").Value Mod 1000

If 1000 - A <= 100 Then MsgBox 1000 - A & " miles to go until you hit " & Format(Range("CG375").Value + 1000 - A, "#,#")
If A > 0 And A <= 10 Then MsgBox "Congratulations! You have now run over " & Format(Range("CG375").Value - A, "#,#") & " miles"

End Sub``````

Replies
8
Views
235
Replies
4
Views
271
Replies
1
Views
194
Replies
26
Views
1K
Replies
4
Views
376

1,186,112
Messages
5,955,909
Members
438,225
Latest member
rsur

### 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.

### Which adblocker are you using?

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

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