MRound VBA formula setting all cell values to zero

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi All,

Thanks in advance for any help you can provide.

I have a formula in VBA which rounds the values in a range to the nearest 0.5.
It works fine but it also sets all the cell values to zero if they are blank, does anyone know a way to get past this?

My code is:

For i = 5 To 20
Sheets(1).Cells(i, 7).Value = Application.MRound(Sheets(1).Cells(i, 7).Value, 0.25)
Next

I have this located in my active sheet under worksheet_change

Thanks again,

Mike
 
Hi Sheetspread,

I was trying to upload a sample spreadsheet so you could see what was happening but can't see an option to upload?

Mike
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi MIke,

Thanks for your help.

I tried your code, it worked in terms of rounding the numbers but rather than opening the message box when the user inputs a range of numbers (21-25) it just seems to allow them to do it.
Also all of the cells in the range are being automatically populated with a Zero value.

Hopefully there's a simple solution :)

Thanks for your help,

Mike
 
Upvote 0

Forum statistics

Threads
1,216,474
Messages
6,130,841
Members
449,598
Latest member
sunny_ksy

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