Data Validation Check on \Column Ranges

Troy Geri

New Member
Joined
May 1, 2013
Messages
2
Hi

I have an excel macro enable spreadsheet, that exports the contents into a text file. It has three columns in the xls that is used to capture amounts with two decimal places and these are formatted as text fields. When the macro runs it left pads the amount columns with zeroes to get a 16 width result in the exported text file and removes the decimals as target system implies the decimals. If decimals are left out and a whole number is entered it screws the result up

Because of this, I can't add normal data validation within the xls to ensure that the amount fields are entered with two decimals and because I need the fields as text I can't use formatting to force the result. Hence I want to build into the macro, a step at the beginning that select the ranges as the three columns I am interested in from rows 2 to 1000 and checks for any cells with no decimal followed by 2 numbers, if found, it should highlight the cell as well as pop up a MsgBox with an error message and end the rest of the macro from running (i.e. abend) until the user fixes all the cells and re-runs

In another forum post a guy did a script that checked for specific values and highlighted cells where the condition was not met. just need mine to be slightly different as it is looking for a decimal + 2 number pattern in the cell and I need the cells not just highlighted but the msgbox and error and rest of macro stops / exits at that point

the other forum post was this one

https://www.mrexcel.com/forum/excel-questions/64901-macro-data-validation.html

thanks for the help guys
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You can get what you want without VBA!:eeek:

If your input data (formatted as numbers) is in column A, use the following formula in an adjacent column to return a text value with two decimal places but no decimal point (e.g. a value entered as 2 will be returned as "200", 1.23 as "123")
= SUBSTITUTE( TEXT( A1, "####,####.00"), ".", "")

Change the number of #s (representing digits) to suit the expected size of your values.
The 00 after the decimal point forces a zero into that position if no other value is entered, so you will always get a value to two decimal places.:biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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