Date Serial VBA

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,208
Hello all, I m using Excel 2007

Can anyone help me please on this issue

Column E:E is populated with Dates IE 12/06/12
In Column AP:AP I need to show as June 12 as a TEXT using the data from column E:E.

IE
12/06/12 June 12
14/12/12 Dec 12
09/02/11 Feb 12

Etc

This needs to be changed using VBA code and I think it can be done using Date Serial but I am unsure how to complete this.
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("E" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Range("AP" & i).Value = Format(Range("E" & i).Value, "mmmm yy")
Next i
End Sub
 

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
Or:

Code:
With Range("AP1:AP" & Range("E" & Rows.Count).End(xlUp).Row) 
       .FormulaR1C1 = "=TEXT(RC[-37],""mmm yy"")" 
    .NumberFormat = "@"   
     .Value = .Value
End With

Dom
 
Last edited by a moderator:

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
Cheers Vog, I'm pretty sure I added them and they vanished. I also then couldn't edit the post for some reason.

Dom
 

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,208

ADVERTISEMENT

Thank you both for your reply, Domski your code works a treat the first time but unless I reformat the column as a date format before re running the code again it just brings over the TEXT Calculation
=TEXT(RC[-37],"mmm yy")

<tbody>
</tbody><colgroup><col></colgroup>
 

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
Fair point:

Code:
With Range("AP1:AP" & Range("E" & Rows.Count).End(xlUp).Row)
    .NumberFormat = "General"
    .FormulaR1C1 = "=TEXT(RC[-37],""mmm yy"")"
    .NumberFormat = "@"
    .Value = .Value
End With

Dom
 

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,208
That's how I solved it also, many thanks again for your help, I see you have posted loads on this site, 6,953 since 2005, That's dedication
 

Watch MrExcel Video

Forum statistics

Threads
1,127,201
Messages
5,623,343
Members
415,969
Latest member
Rey99

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
Top