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
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