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