B
Barney Fyfe
I'd like to prevent a user from entering commas in any of the cells of
a spreadsheet. Is this possible?
Thanks.
a spreadsheet. Is this possible?
Thanks.
I'd like to prevent a user from entering commas in any of the cells of
a spreadsheet. Is this possible?
Thanks.
Yes, you can trigger a comma with a Worksheet_Change-event.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim enteredValue As String
enteredValue = Target.Value
If InStr(1, enteredValue, Chr(44), vbTextCompare) > 0 Then
MsgBox "No comma's allowed!"
Target.Value = vbNullString
End If
End Sub
Moon thank you that worked like a champ. I'm VB illiterate but if I
wanted to perform a replace, how would I do that? Example, say every
time a comma is typed, it automatically gets changed to a tilde (~).
Thanks!
Things change a little bit then. Let's see if the next one also will work:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim enteredValue As String
Dim newValue As String
Dim c, l As Integer
enteredValue = Target.Value
If InStr(1, enteredValue, Chr(44), vbTextCompare) > 0 Then
l = Len(enteredValue)
For c = 1 To l Step 1
If Mid(enteredValue, c, 1) = Chr(44) Then
newValue = newValue & Chr(126)
Else
newValue = newValue & Mid(enteredValue, c, 1)
End If
Next c
Target.Value = newValue
End If
End Sub
On Sun, 3 Jun 2007 02:24:25 +0200, "moon"
Worked exactly as desired. The last question I have is about security.
If the user opens the file and the macros are disabled, what options
do I have? Can I self sign it? If so, how do I lock down your code so
that it cannot be changed?
I appologize for taxing you with all of this but this is scope creep
for me![]()
Yes, but now we're talking about one worksheet - in another worksheetT. Valko said:You can prevent commas from being entered by using data validation and/or
you can use AutoCorrect to change commas to tildes.
Biff
You can prevent commas from being entered by using data validation and/or
you can use AutoCorrect to change commas to tildes.
Biff
Yes, but now we're talking about one worksheet - in another worksheet
AutoCorrect might be a pain in the butt, because it's a global setting.
In this case one worksheet would suffice.
This will work for TEXT entries only:
=AND(ISTEXT(A1),LEN(A1<=12),ISERROR(FIND(",",A1)))
The comma separator in a number is not recognized as a character, it's a
format thing.
1,000,000 will display in the cell but if you look at the formula bar you'll
see 1000000 which is the true underlying value of the cell.
Biff
P.S.
If you preformat the cells as TEXT then you don't need the ISTEXT test:
=AND(LEN(A1)<=12,ISERROR(FIND(",",A1)))
But, it might be a good idea to leave it in.............just in case!
Biff
Here's a good listing of books:
http://contextures.com/xlbooks.html
I think the best way to find a book is to actually go to a book store and
thumb through the books. Pick the one that covers the things you are most
interested in. One of these days I'd like to write my own book on advanced
formulas.
Biff