Trying to force people to not use a comma (even when pasting) or enter a number in a specific format

dumahim

New Member
Joined
Aug 16, 2024
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Been banging my head against the wall for an hour on this.

I need a way to completely block a comma from being in a row, either typed in or pasted in, and/or force them to only input a valid number that includes 3 decimal places. Again typed or pasted. I've tried a couple things, but there always seems to be a way around it.
The number represents a number of shares and goes out to 3 decimal places. I have the cells formatted to be that way, but we've had some MASSIVE problems over the last few years where someone will either miss entering the period or they hit the comma instead. Because the way the cell is formatted to always go out the 3 decimal places, if they enter a comma or miss the period, it turns something like 256.134 shares into 256134.000 shares.

1) I tried Conditional Formatting to highlight a cell if a comma is entered. Problem is, most of the time this info is being copied from somewhere else and pasting is clearing the conditional formatting.
2) I tried Data Validation to throw an error if a comma is entered, but again, pasting the info in bypasses the Data Validation.

I could apply either of these methods to where they're getting the info from, as we strongly prefer people to be copying and pasting the info to avoid typos, but some people are just going to do their own thing and probably paste into that area anyway. I've seen some VBA solutions, but I'm very much an amateur with that and I'm not following what's being said or how to apply that to my situation. Not to mention, I'm not even sure if copying and pasting will get around that anyway.

So the bottom line is, I need a column to never allow a comma under any circumstance, typed or pasted in and/or only use a number value that already has the decimals there (this would cover the event where people missing the period). Any help with this would be greatly appreciated.
 
I should have repeated the caveat.
.. & I should have read the earlier post more carefully. :)

BTW, I suspect in both your codes you would have meant "For Each cel in rng" Rather than "For Each cel in Target"?
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
.. & I should have read the earlier post more carefully. :)

BTW, I suspect in both your codes you would have meant "For Each cel in rng" Rather than "For Each cel in Target"?
Yes, it should be "For Each cel in rng" . Thanks.
 
Upvote 0
For post 4 if the user enters "123.450", which seems a correct entry with 3 decimal places, the code removes it as an invalid entry.
@Peter_SSs
If the OP formats the desired column to 'Text', that should solve the problem you mentioned.
 
Upvote 0
@Peter_SSs
If the OP formats the desired column to 'Text', that should solve the problem you mentioned.
It would allow the entry I mentioned but then that would allow an entry like 6,236.231 which contains a comma and it would also mean that any calculations based on the entries may be difficult since they are text.
The code (whether the cell is formatted as text or not) also allows an entry like 3,3.326 or 3.456.456 where the user may have accidentally hit "." instead of "," in the first instance which doesn't enforce ..
and/or force them to only input a valid number that includes 3 decimal places.

@dumahim
One other thing to consider: You have mentioned how Conditional Formatting and Data Validation can be defeated by Copy/Paste but also note that any vba solution would also be defeated if the user does not have macros enabled.
 
Upvote 0
@dumahim
One other thing to consider: You have mentioned how Conditional Formatting and Data Validation can be defeated by Copy/Paste but also note that any vba solution would also be defeated if the user does not have macros enabled.

That isn't an option for the people using the sheets.
 
Upvote 0
What if the OS or excel configuration is set so that coma "," is set as decimal separator and period "." is set as thousands separator?
Any VBA solution wont work, and you will have erroneous data input.
IMHO you solution should focus on some other way of checking for correctness of the data rather than prevent a specific character to be inputted.
 
Upvote 0
So, do any of the above suggestions meet your requirements?
See my initial reply. I can't get either of the proposed codes to work correctly.
 
Upvote 0
What if the OS or excel configuration is set so that coma "," is set as decimal separator and period "." is set as thousands separator?
Any VBA solution wont work, and you will have erroneous data input.
IMHO you solution should focus on some other way of checking for correctness of the data rather than prevent a specific character to be inputted.
W11 and 365

What other solution would you suggest if VBA won't work for this?
 
Upvote 0
Messing it with it some more, the method mumps provided, I'm not running into the same problem I was having the other day with typing in bad info rather than pasting it. Just the issue with it giving the error for columns C-G and an endless loop of the error if I use my clearcontents macro to clear all the cells.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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