RockandGrohl
Well-known Member
- Joined
- Aug 1, 2018
- Messages
- 790
- Office Version
- 365
- Platform
- Windows
Hi, really not sure how to make the title sound like what I want to do.
I have a user-set date which is input as Mmm-YY (Oct-21 for instance) - when placed in a cell it's listed as 01/10/2021 which is absolutely fine, the format is set as "Oct-21" so it's perfect.
I'd like to put the previous 5 months in cells to the left. Say Oct-21 is in cell L4, I'd like a macro to just but Sep-21 in K4, Aug-21 in J4 etc until it gets to May-21 where it inputs that and stops.
This is the sort of thing I could do with my eyes closed but after an extended break from VBA, I simply can't remember Sad face.
EDIT: I'm a long way off testing, would this work bychance?
I need RepDate to take 10-21 and convert it to 01/10/2021
I have a user-set date which is input as Mmm-YY (Oct-21 for instance) - when placed in a cell it's listed as 01/10/2021 which is absolutely fine, the format is set as "Oct-21" so it's perfect.
I'd like to put the previous 5 months in cells to the left. Say Oct-21 is in cell L4, I'd like a macro to just but Sep-21 in K4, Aug-21 in J4 etc until it gets to May-21 where it inputs that and stops.
This is the sort of thing I could do with my eyes closed but after an extended break from VBA, I simply can't remember Sad face.
EDIT: I'm a long way off testing, would this work bychance?
VBA Code:
RepDate = InputBox("Please enter date in MM-YY format", "Enter Date")
Range("L4").Value = Format(RepDate, "Mmm-YY")
Range("K4").Activate
x = -1
Do Until Cells(ActiveCell.Column) = 7
ActiveCell.Value = Format(DateAdd("m", x, RepDate), "Mmm-YY")
x = x - 1
ActiveCell.Offset(0, -1).Activate
Loop
I need RepDate to take 10-21 and convert it to 01/10/2021
Last edited: