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
[TABLE="width: 449"]
<tbody>[TR]
[TD]Date
[/TD]
[TD]Used Formel =TEXT(A1;"åååå")
[/TD]
[TD]With VBA macro
[/TD]
[/TR]
[TR]
[TD="align: right"]10-12-57
[/TD]
[TD]1957
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]24-12-2017
[/TD]
[TD]2017
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2013-12-02
[/TD]
[TD]2013
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]21-12-2013
[/TD]
[TD]2013
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]24-12-2017
[/TD]
[TD]2017
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]21-12-2013
[/TD]
[TD]2013
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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. :laugh:
Thank you very much
Best regards Keld
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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