메인 컨텐츠로 가기

특정 셀에서 날짜 형식 만 허용하는 방법은 무엇입니까?

Excel 워크 시트에 날짜 형식 만 입력 할 수 있도록 셀 목록을 제한하는 방법은 무엇입니까? 이 기사에서는이 일을 다루는 몇 가지 흥미로운 트릭에 대해 이야기 할 것입니다.

데이터 유효성 검사 기능을 사용하여 특정 셀의 날짜 형식 만 허용

VBA 코드가있는 특정 셀의 날짜 형식 만 허용


화살표 블루 오른쪽 거품 데이터 유효성 검사 기능을 사용하여 특정 셀의 날짜 형식 만 허용

Excel에서 데이터 유효성 검사 는 드롭 다운 목록 생성, 중복 입력 방지 등을 도와주는 강력한 기능입니다. 또한 특정 셀에 다른 데이터 형식을 입력하지 않고 날짜 형식 만 입력하는 것을 방지 할 수 있습니다. 다음 단계를 수행하십시오.

1. 딸깍 하는 소리 Data > 데이터 유효성 검사 > 데이터 유효성 검사, 스크린 샷 참조 :

문서 허용 날짜 1

2. 에서 데이터 유효성 검사 대화 상자에서 설정 탭을 선택한 다음 관습 인사말 허용 드롭 다운 목록에 다음 공식을 입력하십시오. = AND (ISNUMBER (B2), LEFT (CELL ( "형식", B2), 1) = "D")공식 텍스트 상자, 스크린 샷 참조 :

문서 허용 날짜 2

주의 사항: 위의 공식에서 B2 데이터 형식을 제한하려는 열의 첫 번째 셀입니다.

문서 허용 날짜 3

3. 그런 다음 클릭하십시오. 오류 경고 대화 상자의 탭에서 다음 작업을 수행하십시오.

(1.) 확인 유효하지 않은 데이터 입력 후 오류 경고 표시 선택권;

(2.) 아래 스타일 드롭 다운, 선택하십시오 중지 선택권;

(3.) Title에러 메시지 프롬프트 상자에 표시 할 것입니다.

4. 설정을 마친 후 OK 버튼을 누르면 실제 날짜 형식이 아닌 데이터를 입력하면 다음과 같은 스크린 샷과 같이 알려주는 프롬프트 상자가 나타납니다.

문서 허용 날짜 4


화살표 블루 오른쪽 거품 VBA 코드가있는 특정 셀의 날짜 형식 만 허용

두 번째 방법은 VBA 코드를 소개합니다.

1. 사용할 워크 시트를 활성화하십시오.

2. 그런 다음 시트 탭을 마우스 오른쪽 버튼으로 클릭하고 코드보기 컨텍스트 메뉴에서 스크린 샷을 참조하십시오.

문서 허용 날짜 5

3. 표시된 응용 프로그램 용 Microsoft Visual Basic 창에서 아래 코드를 복사하여 모듈, 스크린 샷 참조 :

VBA 코드 : 특정 셀에 날짜 형식 입력 만 허용 :

Private Sub Worksheet_Change(ByVal Target As Range)
'updateby Extendoffice
Set w = ActiveSheet.Range("B2:B12")
For Each c In w
If c.Value <> "" And Not IsDate(c) Then
c.ClearContents
MsgBox "Only a date format is permitted in this cell."
End If
Next c
End Sub

문서 허용 날짜 6

4. 그런 다음 광고를 저장하고 코드를 닫습니다. 이제 B2 : B12 범위에 날짜 형식이 아닌 값을 입력하면 알림 상자가 나타나고 동시에 셀 값이 지워집니다. 스크린 샷 참조 :

문서 허용 날짜 7

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!

 

Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Buenos dias

Estoy utilizando la formula en la validación de datos pero no me deja ingresar ningún formato de fecha, me puede explicar por favor

Muchas gracias
This comment was minimized by the moderator on the site
Hi I want to restrict the Date Format in DD.MM.YYYY in excel
May please suggest
This comment was minimized by the moderator on the site
Hello, Ramesh
To restrict the Date Format in DD.MM.YYYY, you can apply the below code:
Note: Please change the cell reference B2:B12 to your own list of cell.
Private Sub Worksheet_Change(ByVal Target As Range)
'updateby Extendoffice
    On Error Resume Next
    
    Dim Bool As Boolean
    Dim Rg As Range
    Dim xRegEx As Object
    
    Bool = False

    Set Rg = Application.Intersect(Target, ActiveSheet.Range("B2:B12"))
    If Rg Is Nothing Then Exit Sub

    Set xRegEx = CreateObject("VBSCRIPT.REGEXP")
    With xRegEx
        .Pattern = "^[0-3]\d\.[0-1][0-2]\.\d{4}$"
        .Global = True
        .IgnoreCase = True
    End With
    
    Application.EnableEvents = False
    For Each c In Target
        If c.Value <> "" Then
            If Not xRegEx.test(c.Text) Then
                c.ClearContents
                Bool = True
            End If
        End If
    Next c
    Application.EnableEvents = True
    If Bool Then
        MsgBox "Error date format."
    End If
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hello,Sorry for refreshing, the code works very nice, thank you. I just want to add one more check if its possible.Is it possible to check cell on the left if it contain certain value. Basically what I need is: if cell on the left contain N then that cell in range have to be input as a date.If cell on the left is Y then that cell needs to stay blank.
This comment was minimized by the moderator on the site
How can I oblige to enter a time? (hh:mm)Private Sub Worksheet_Change(ByVal Target As Range)
'updateby Extendoffice 20150530
Set w = ActiveSheet.Range("B2:B12")
For Each c In w
If c.Value <> "" And Not IsDate(c) Then <----------------------------And Not isTime(c) doesn't work!
c.ClearContents
MsgBox "Only a date format is permitted in this cell."
End If
Next c
End Sub
This comment was minimized by the moderator on the site
Hello, Roberto,

To only allow time format to be entered, you should apply the below code:



Private Sub Worksheet_Change(ByVal Target As Range)

'updateby Extendoffice

Dim xArr As Variant

Dim xF As Integer

Dim xB As Boolean

Dim xWRg, xCRg As Range

Set xWRg = ActiveSheet.Range("B2:B20")

For Each xCRg In xWRg

xArr = Split(xCRg.Value, ":")

xB = False

If UBound(xArr) <= 2 Then

For xF = LBound(xArr) To UBound(xArr)

If IsNumeric(xArr(xF)) Then

If xF = 0 Then

If (xArr(xF) > 0) And (xArr(xF) < 24) Then

Else

xB = True

GoTo BTime

End If

Else

If (xArr(xF) > 0) And (xArr(xF) < 60) Then

Else

xB = True

GoTo BTime

End If

End If

Else

xB = True

GoTo BTime

End If

Next

Else

MsgBox "Only a time format is permitted in this cell."

xCRg.ClearContents

End If

BTime:

If xB Then

MsgBox "Only a time format is permitted in this cell."

xCRg.ClearContents

End If

Next xCRg

End Sub



Please try it, thank you!
This comment was minimized by the moderator on the site
Thank you so much, for the VBA code to be applied to multiple columns can you please provide the formula?.. I tried but ended up getting a 405 error!
This comment was minimized by the moderator on the site
Hello, Kevin,
To make the code applied for multiple ranges, you just need to add the cell references into the code as below:

Private Sub Worksheet_Change(ByVal Target As Range)
Set w = ActiveSheet.Range("B2:B12,A1:A10,C5:C20")
For Each c In w
If c.Value <> "" And Not IsDate(c) Then
c.ClearContents
MsgBox "Only a date format is permitted in this cell."
End If
Next c
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Thanks a lot @skyyang, really appreciate your help :)
This comment was minimized by the moderator on the site
how to add a date validation for date format "DD-mmm-yyy" (15-Dec-2018) like this
This comment was minimized by the moderator on the site
which date format is this function allowed. It is not working for some dates
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations