Change Date format to (dd-mmm-yy) if the inserted values are Date , Not Work?

Waleed78

I need Change Date format to (dd-mmm-yy) if the inserted values are Date ,But it is Not Work !

the current result format is dd-mm-yy and the expected is dd-mmm-yy. I tried the below code. as always,any help will be appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)

  If Not Intersect(Target, Columns("E:F")) Is Nothing Then  'Change Date format to dd-mmm-yy
  
        If Not IsDate(Target.value) = False Then
         
         Target.NumberFormat = "dd-mmm-yy"
         
         End If
       End If

End Sub
BigBen

You probably need to loop, if you're changing multiple cells at once. Note that changing the number format doesn't change the underlying value. If you're working with text-that-looks-like-a-date, changing the number format won't do anything. You'd need to convert it to a date first (maybe using CDate or DateValue).

Dim rng As Range
Set rng = Intersect(Target, Columns("E:F"))

If Not rng Is Nothing Then
   Dim cell As Range
   For Each cell In rng
       If IsDate(cell.Value) Then
           cell.NumberFormat = "dd-mmm-yy"
       End If
   Next
End If

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Converting string format dd - mmm - yy to date

Android - change Date Format to dd/mm/yy

Match date in dd-MMM-yy format to yyyy-MM-dd in Hive

Date format dd/mm/yy

How to change Date format (dd-mmm-yyyy) in bootstrap datepicker

How can I get datetime today date from C# with format 'dd-MMM-yy'

Converting a mmm-yy date in string format to date format

How to change date format (MM/DD/YY) to (YYYY-MM-DD) in date picker

puzzled with how to convert ddmmyy string to dd-MMM-yy date

sort array of date of format 'dd/mmm/yyyy'

Format date to DD-MMM-YYYY in Javascript

Check date format is DD-MMM-YYYY

SAS numeric date format to dd/mm/yy

Parsing date format of mmm dd yyyy to excel date format

How to change/convert input date format from MM dd yy to yyyy-mm-dd on submit

How to change Date Format dd-mm-yy to yyyy-mm-dd

JQuery Datepicker date format - How to change from dd/mm/yyyy to dd/mm/yy?

Python change the date format from dd/mm/yy to dd/mm/yyyy for the dates before 1970

Change date format from m/dd/yy to yyyy/MM/dd in Java

Convert MMM-YY string into Sortable Date Format

VBA Date values when inserted to Excel cells change their format

date format yyyy-mm-dd to dd-M-yy

Convert Timestamp string (dd MMM yyyy HH:mm:ss) to Date (DD/MM/YY) in Google Sheets

How to change Date format in `Jquery mask plugin` from dd/mm/yyyy to mm/yy?

Temporarily change format of a date column in SQL Query output MM/YY -> MM/DD/YYYY

R How to change format of date from MM/DD/YYYY to YYYYMMDD and YY-Month (Abbreviated Month)?

Change string "dd/mm/yy HH:mm:ss" into accepted date/time format

How to change format of a numpy array of date from YYYY-MM-DD to MM - YY

how can i change date format to mmm-yy for cells ranging from A2: J2 in excel using python