Converting date from cell to month as mmm VBA

saadn

New Member
Joined
Apr 1, 2017
Messages
11
Hi,

I've got dates in column A in dd/mm/yyyy format and I need to extract the month number in mmm format in column H vba. I've used the following code to get the date into column H but cannot get it in mmm format.

Dim y As Integer
On Error Resume Next
For y = 1 To 10


If Not Cells(y, 1) = "Date" And Cells(y, 8) = "" Then
Cells(y, 8).Select
ActiveCell.Value = Cells(y, 1)

The reason I need to do this is each month bank statement data will be pasted into a tab and based on the month selected on the control sheet, the transactions for that particular month will be split between payments and receipt and moved to tabs called "payments" and "receipts" respectively. I was going to use the above code to extract the month from the date and based on what month is selected in the control sheet, write coding to pick up a transaction, work out if it is a payment and receipt and then move it. If there is a better way I can do this, that would help.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
cells(y, "H") .value = format(cells(y,"A").value, "mmm")
 
Upvote 0
Or

Code:
cells(y, "H").value = cells(y,"A").value
cells(y, "H").numberformat = "mmm"
 
Upvote 0
Or

Code:
cells(y, "H").value = cells(y,"A").value
cells(y, "H").numberformat = "mmm"

Thanks but this is converting the "dd" to the month so if the date is 01/04/2018 (1 April 2018) it is setting the "mmm" as "Jan".
 
Upvote 0
Also, I need to final cell to actually contain "Apr" as text and not as a date formatted as "mmm"
 
Upvote 0
Try...

Code:
Cells(y, "H").Value = Format(CLng(Cells(y, "A").Value), "mmm")
 
Upvote 0
Try...

Code:
Cells(y, "H").Value = Format(CLng(Cells(y, "A").Value), "mmm")
doesn't seem to be doing anything?

I've got
Dim y As Integer
On Error Resume Next
For y = 1 To 10




If Not Cells(y, 1) = "Date" And Cells(y, 8) = "" Then
Cells(y, 8).Select
ActiveCell.Value = Cells(y, 1)
Cells(y, "H").Value = Format(CLng(Cells(y, "A").Value), "mmm")


Else
End If
Next y
 
Upvote 0
This code
Code:
Sub vvvv()
    Dim y As Integer
    For y = 1 To 10

        If Not Cells(y, 1) = "Date" And Cells(y, 8) = "" Then
            Cells(y, "H").Value = Format(CLng(Cells(y, "A").Value), "mmm")
        End If
    Next y
End Sub

gives me this result


Excel 2010
ABH
101/04/2018Apr
201/05/2018May
3Date
401/07/2018Jul
501/08/2018Aug
601/09/2018Sep
7Date
801/11/2018Nov
901/12/2018Dec
10Date
Sheet2


When column H was blank.
 
Last edited:
Upvote 0
I copied and pasted that and am getting "runtime error 13 type mis-match" which highlights
"Cells(y, "H").Value = Format(CLng(Cells(y, "A").Value), "mmm")"

edit: it's because the format of my date range is not "short date". I need to put a code in to do that first I guess
 
Last edited:
Upvote 0
Put =ISNUMBER(A3) in a blank cell (change A3 to another cell in the range if it isn't a cell with a date in it).
Does it return TRUE or FALSE?
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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