calculate month from date

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
339
Office Version
  1. 2016
Platform
  1. Windows
I have a sheet where Col A lists (thousands) of dates, and in Col C the respective months are calculated.

I do this with the below code, however this takes a few second (over 100K dates).

Any way to speed this up ?

Thanks.

VBA Code:
Private Sub Worksheet_Activate()
Dim i As Long
Dim nRow As Long

nRow = Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To nRow
    Range("C" & i).Formula = "=TEXT(A" & i & ",""yyyy/mm"")"
Next i


End Sub
 

Attachments

  • dates.png
    dates.png
    17 KB · Views: 17

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try thí
VBA Code:
Private Sub Worksheet_Activate()
Dim nRow As Long

nRow = Range("A" & Rows.Count).End(xlUp).Row
Range("C2:C" & nRow).Value = "=TEXT(RC[-2],""yyyy/mm"")"

End Sub
 
Upvote 0
Another one:
VBA Code:
Private Sub Worksheet_Activate()
    Range("C2").Formula = "=TEXT(A2,""yyyy/mm"")"
    Range("C2").AutoFill Destination:=Range("C2:C" & Cells(Rows.Count, 1).End(xlUp).Row), Type:=xlFillDefault
End Sub
 
Upvote 0
Solution
Thanks John, works fine. Thanks also to Phuoc. I will also keep your suggested solution on my records.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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