Numeric value only in a cell (no dates)

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
579
Office Version
  1. 2016
I need to somehow have a whole numeric value in a cell (but not allow a date input). The numeric value can be anything from 0-6 digits long. (i.e. can i stop the following symbols being put in to prevent this . / - ?
 

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)
Yes, it's an invalid date, so it will be treated as text.

You want to use AND() function to handle the rest, something like AND(ISNUMBER(A1),LEFT(CELL("format",A1))<>"D",OTHER_CONDITIONS)
In other conditions you can require other things, like character min max length, make sure it's a whole number, etc., just separate each with a comma in your AND function.
 
Upvote 0
Thanks for your help - where I am new to this can you help me with the second part of the formula to.

- Need to length to be between 0 and 6 characters
- Only whole numbers
- No alpha or special characters

Yes, it's an invalid date, so it will be treated as text.

You want to use AND() function to handle the rest, something like AND(ISNUMBER(A1),LEFT(CELL("format",A1))<>"D",OTHER_CONDITIONS)
In other conditions you can require other things, like character min max length, make sure it's a whole number, etc., just separate each with a comma in your AND function.
 
Upvote 0
Thanks for your help - where I am new to this can you help me with the second part of the formula to.

- Need to length to be between 0 and 6 characters
- Only whole numbers
- No alpha or special characters

Try this:
Code:
=AND(ISNUMBER(A1),LEFT(CELL("format",A1))<>"D",MOD(A1,1)=0,LEN(A1)<7)
 
Last edited:
Upvote 0
Data Validation will restrict user entry to the cell to values between 100000 and 999999.

All that one needs to do at that point is insure that the cell remains in general format and doesn't automatically change to a date format. You can do that with this change event.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Target.NumberFormat = ""
End Sub
 
Upvote 0
I have found a nice little workaround, which is as follows :


I have preformatted the cell as text "@", so that Excel will not try to interpret any input.

Then using data validation , I have input the following as a custom formula :
Rich (BB code):
 =IFERROR(FIND("/",A1),-1)<0    



Data Validation will restrict user entry to the cell to values between 100000 and 999999.

All that one needs to do at that point is insure that the cell remains in general format and doesn't automatically change to a date format. You can do that with this change event.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Target.NumberFormat = ""
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,310
Members
448,955
Latest member
Dreamz high

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