Convert dates to text with a Vba macro

KeldAlmand

New Member
Joined
Nov 22, 2017
Messages
2
Hi could anyone help me with this problem, I would be very happy.

I want to draw year as TEXT out from dates in a column with Vba

My Test Sheet is like this
Date
Used Formel =TEXT(A1;"åååå")
With VBA macro
10-12-57
1957
24-12-2017
2017
2013-12-02
2013
21-12-2013
2013
24-12-2017
2017
21-12-2013
2013

<tbody>
</tbody>
Here is my code that don't work

Sub FindYearFormDateAndInsertItAsTEXT()
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
FinalRow = Cells(Rows.Count, 2).End(xlUp).Row
' Run trough all rows and set values from Coloumn A as Year, as text, in coloumn C
For i = 2 To FinalRow
If Cells(i, 1) = "" Then
Cells(i, LastCol).Value = "Empty"
Else: Cells(i, LastCol).Formula = TEXT(Cells(i, 1("åååå") ' This line is the tricky part
End If
End Sub

Best regards Keld
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Does this do what you want?

Code:
Sub FindYearFormDateAndInsertItAsTEXT()
Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=IF(A2="""",""Empty"",TEXT(A2,""yyyy""))"
End Sub
 
Upvote 0
Hi Scott, It works I had just to replace the yyyy with åååå then it does exact what I wanted. :LOL:
Thank you very much
Best regards Keld
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,537
Members
449,088
Latest member
RandomExceller01

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