Convert date automatically to “mmm” format

David_8055

New Member
Joined
Jul 6, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
Hi all,
Can I know how to get month in “mmm” format if I have a date in its previous column.
For eg: column A contains date in short format.
I want column B to show only the month in “mmm” format based on the date in column A. Similarly column C will show only the year in “yyyy” format.
How to do this via VBA? Any help pls
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
VBA Code:
Format(Date, "mmm")
VBA Code:
Format(Date, "yyyy")
 
Upvote 0
VBA Code:
Format(Date, "mmm")
VBA Code:
Format(Date, "yyyy")
Thanks got the reply. But that wont work in this scenario.
My column A is 1/4/2022
How can Column B look at this value and enter only the month as “mmm”?
Similarly Column C look at column A and show only the year as “yyyy”
 
Upvote 0
It depends on how you want it to happen:

Do you want B & C to auto complete when a date is entered in column A?
Does it have to be VBA or can it be formula?

If formula then:
B formula:
Excel Formula:
=TEXT(A1,"MMM")
C formula:
Excel Formula:
=TEXT(A1,"YYYY")
 
Upvote 0
It depends on how you want it to happen:

Do you want B & C to auto complete when a date is entered in column A?
Does it have to be VBA or can it be formula?

If formula then:
B formula:
Excel Formula:
=TEXT(A1,"MMM")
C formula:
Excel Formula:
=TEXT(A1,"YYYY")
It gotta be vba as it runs along with my other code. Yes autocomplete
 
Upvote 0
I see, is your other code a worksheet change event?
Does your other code put the date in column A?

I am trying to figure out what the trigger would be for the code to run, would it be the date being entered in column A?
 
Upvote 0
I see, is your other code a worksheet change event?
Does your other code put the date in column A?

I am trying to figure out what the trigger would be for the code to run, would it be the date being entered in column A?
Ok, basically my file is a monthly report kind of data.
I use my code to extract certain columns automatically to sheet2 every time I open my excel. Lets say if new data is being added into sheet1, upon running my code desired values will be automatically uploaded in sheet2.
Now this data contains date in 1 column. I would like to extract month and year separately to 2 new columns namely under month and year. This should be updated automatically when I run the code.
 
Upvote 0
Try:
VBA Code:
Sub test()
Dim lr&, i&, rng, arr()
lr = Cells(Rows.Count, "A").End(xlUp).Row
rng = Range("A1:A" & lr).Value
ReDim arr(1 To lr, 1 To 2)
On Error Resume Next
For i = 1 To lr
    If IsDate(rng(i, 1)) And rng(i, 1) <> "" Then
        arr(i, 1) = Format(rng(i, 1), "mmm")
        arr(i, 2) = Format(rng(i, 1), "yyyy")
    End If
Next
Range("B1").Resize(UBound(arr), 2).Value = arr
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,739
Messages
6,180,676
Members
452,993
Latest member
FDARYABEE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top