Paste the month an year in cells

Peterso

Board Regular
Joined
Nov 28, 2012
Messages
113
In Sheet 1 cell(1,1) I have a date, say 2-Jul-1998. And in cell(2,1) I have another date, say 24-Feb-2024. I want to put in Sheet(2), cell(4,4).value=Jul-1998, cells(4,5).value=Aug-1998.......Cells(4,k).value=Feb-2024. how to write the macro? Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
What version of Excel are you using? ...which, by the way, you should add to your profile.
 
Last edited:
Upvote 0
In Cell(4,4) of sheet2
Excel Formula:
=LET(a,Sheet1!A1,b,Sheet1!A2,DATE(YEAR(a),SEQUENCE(YEAR(b)*12+MONTH(b)+1-YEAR(a)*12-MONTH(a),1,MONTH(a),1),1))
Format result cells for Mmm-yy
 
Last edited:
Upvote 0
I thought you said you wanted a macro? If that is still the case, here is one. Note that the macro will automatically handle formatting the cells for you.
VBA Code:
Sub SequenceMonthYearBetweenDates()
  Dim X As Long, Arr As Variant
  With Sheets("Sheet1")
    ReDim Arr(1 To 1, .Range("A2").Value - .Range("A1").Value + 1)
    For X = 1 To .Range("A2").Value - .Range("A1").Value + 1
      Arr(1, X) = WorksheetFunction.EoMonth(X + .Range("A1").Value - 1, 0)
    Next
  End With
  Arr = WorksheetFunction.Unique(Arr, 1)
  With Sheets("Sheet2").Range("D4").Resize(, WorksheetFunction.CountA(Arr))
    .Value = Arr
    .NumberFormat = "mmm-yyyy"
  End With
End Sub

However, if a formula solution is okay (you will have to format the cells manually), then give this a try...
Excel Formula:
=LET(a,Sheet1!A1,b,Sheet1!A2,UNIQUE(EOMONTH(SEQUENCE(,b-a+1,a),0),1))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,665
Messages
6,161,130
Members
451,686
Latest member
NSRL

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