Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
hui hui is offline
external usenet poster
 
Posts: 9
Default how to set column check

I made a worksheet store employee information. I hope when someone write
data in Column Birthday (Formated YYYY-MM-DD), the worksheet would
automatically check if the data is formated with YYYY-MM-DD, if not, it
would warn user. is it ok in worksheet?

thanks in advance.

hui


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default how to set column check

This uses column A as an example.
First format the cells in column A as text.
Then enter the following macro in wroksheet code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Columns("A")) Is Nothing Then
Exit Sub
End If
Dim v As String
v = Target.Value
v2 = WorksheetFunction.Substitute(v, "-", "")

If Len(v2) < 8 Then
MsgBox ("bad input")
Exit Sub
End If

If IsNumeric(v2) Then
Else
MsgBox ("bad input")
Exit Sub
End If

v3 = Split(v, "-")
If Len(v3(0)) < 4 Or Len(v3(1)) < 2 Or Len(v3(2)) < 2 Then
MsgBox ("bad input")
Exit Sub
End If

If v3(1) 12 Or v3(2) 31 Then
MsgBox ("bad input")
Exit Sub
End If
End Sub
--
Gary's Student


"hui" wrote:

I made a worksheet store employee information. I hope when someone write
data in Column Birthday (Formated YYYY-MM-DD), the worksheet would
automatically check if the data is formated with YYYY-MM-DD, if not, it
would warn user. is it ok in worksheet?

thanks in advance.

hui



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
hui hui is offline
external usenet poster
 
Posts: 9
Default how to set column check

thanks, very nice

I always focus on worksheet functions. :) you told me another way to resolve
my problem.

thank you

hui
"Gary''s Student" ...
This uses column A as an example.
First format the cells in column A as text.
Then enter the following macro in wroksheet code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Columns("A")) Is Nothing Then
Exit Sub
End If
Dim v As String
v = Target.Value
v2 = WorksheetFunction.Substitute(v, "-", "")

If Len(v2) < 8 Then
MsgBox ("bad input")
Exit Sub
End If

If IsNumeric(v2) Then
Else
MsgBox ("bad input")
Exit Sub
End If

v3 = Split(v, "-")
If Len(v3(0)) < 4 Or Len(v3(1)) < 2 Or Len(v3(2)) < 2 Then
MsgBox ("bad input")
Exit Sub
End If

If v3(1) 12 Or v3(2) 31 Then
MsgBox ("bad input")
Exit Sub
End If
End Sub
--
Gary's Student


"hui" wrote:

I made a worksheet store employee information. I hope when someone write
data in Column Birthday (Formated YYYY-MM-DD), the worksheet would
automatically check if the data is formated with YYYY-MM-DD, if not, it
would warn user. is it ok in worksheet?

thanks in advance.

hui





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
Copying forumla for vlook up but changing the column Index # klafert Excel Worksheet Functions 21 September 4th 06 07:56 PM
macro unouwanme Excel Discussion (Misc queries) 9 August 31st 06 09:38 PM
Check COlumn - Excel VBA magix Excel Discussion (Misc queries) 11 November 5th 05 02:32 AM
match and count words David Excel Worksheet Functions 5 July 4th 05 02:24 AM
Return Count for LAST NonBlank Cell in each Row Sam via OfficeKB.com Excel Worksheet Functions 12 April 17th 05 10:36 PM


All times are GMT +1. The time now is 10:28 PM.

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

About Us

"It's about Microsoft Excel"