Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default restricting data entry to non-times

I actually need to have entries in some cells to be numbers or text
but NOT times.
Thus I need the cells formatted as General. General formatting makes
10:00 show up as 0.416667. I need data entries to be restricted to
non-
times. Can I have data validation set up to restrict time entries only
but still be able to enter numbers that can be used in formulas?
I have tried =Right(A1,3)=":" in the custom setting under data
validation but
that doesn't seem to workThanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default restricting data entry to non-times

This little macro will do the same thing:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim s As String

If Intersect(Target, Range("G16")) Is Nothing Then
Exit Sub
End If

s = Target.NumberFormat
If InStr(1, s, ":") 0 Then
Application.EnableEvents = False
Target.Clear
Target.Select
Application.EnableEvents = True
MsgBox ("Times not allowed")
End If
End Sub

This sample checks entries in cell G16.

If the user types an entry that Excel recognizes as a time, Excel will
change the format from General to a time-style format. The macro looks for a
colon in the cell format and responds accordingly.

If text is entered rather than time:

HELLO:WORLD

the macro will allow it.
--
Gary''s Student - gsnu200730
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,344
Default restricting data entry to non-times

Hi,

My first attempt to Post this appeared to fail, so here goes again:

You can also use the following macro which incorporates a couple of other
potentially useful ideas:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Err1
If Intersect(Target, [A1:B30]) Is Nothing Then Exit Sub
With Target
If Left(.NumberFormat, 1) = "h" Then
Application.EnableEvents = False
.Clear
.Select
MsgBox "Times are not allowed."
End If
End With
Err1:
Application.EnableEvents = True
End Sub

--
Cheers,
Shane Devenshire


" wrote:

I actually need to have entries in some cells to be numbers or text
but NOT times.
Thus I need the cells formatted as General. General formatting makes
10:00 show up as 0.416667. I need data entries to be restricted to
non-
times. Can I have data validation set up to restrict time entries only
but still be able to enter numbers that can be used in formulas?
I have tried =Right(A1,3)=":" in the custom setting under data
validation but
that doesn't seem to workThanks


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting data entry to unique entries only in a specific range Illya Teideman Excel Discussion (Misc queries) 10 August 30th 07 01:08 PM
Restricting data entry to A-Z a-z 0-9 Illya Teideman Excel Discussion (Misc queries) 10 August 28th 07 07:33 PM
Restricting entry in B1 on the basis of entry in A1 Biff Excel Worksheet Functions 0 December 3rd 05 03:41 AM
Restricting data entry JT Excel Programming 1 August 19th 05 08:39 PM
Help With Restricting Values in Data Entry Forms please Carnage Excel Programming 1 May 27th 04 11:41 AM


All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"