Alan in NJ
New Member
- Joined
- Feb 1, 2016
- Messages
- 10
Each week I have a spreadsheet in which column A has the start date and column B has the end date of an event, unless it is a one-day event in which case column B is either blank or has the same date as column A. I needed to create a new text column that contains the date reformatted into one of the following four forms: Dec 26 2017-Jan 9 2018 (different year), Mar 29-Apr 10 2017 (different month, same year), Mar 20-22 2017 (same month), Mar 21 2017 (one-day event).
I have handled this by adding six "helper" columns to the spreadsheet and separating out the following using the TEXT function: start date: mmm (col. C), d (col. D), yyyy (col. E) and end date: mmm (col. F), d (col.G), yyyy (col. H) and then using the following formula in a seventh column to populate it with the date in the new format:=IF(OR(B2="",B2=A2),C2&" "&D2&" "&E2,IF(E2<>H2,C2&" "&D2&" "&E2&"-"&F2&" "&G2&" "&H2,IF(C2<>F2,C2&" "&D2&" "&E2&"-"&F2&" "&G2&" "&H2,C2&" "&D2&"-"&" "&G2&" "&H2))).
This works fine, but it would be better if I had a macro that would allow me to highlight the two columns with the start date and end date and then have the adjacent (empty) column to the right populated with the newly formatted date. I envision either a temporary array or simply temporarily adding the same helper columns I populate with my functions above and then deleting them before the macro terminates.
I searched previous "date" posts but didn't find anything on point. Any assistance would be appreciated. Hopefully, my legwork makes this relatively easy for someone familiar with VBA.
I have handled this by adding six "helper" columns to the spreadsheet and separating out the following using the TEXT function: start date: mmm (col. C), d (col. D), yyyy (col. E) and end date: mmm (col. F), d (col.G), yyyy (col. H) and then using the following formula in a seventh column to populate it with the date in the new format:=IF(OR(B2="",B2=A2),C2&" "&D2&" "&E2,IF(E2<>H2,C2&" "&D2&" "&E2&"-"&F2&" "&G2&" "&H2,IF(C2<>F2,C2&" "&D2&" "&E2&"-"&F2&" "&G2&" "&H2,C2&" "&D2&"-"&" "&G2&" "&H2))).
This works fine, but it would be better if I had a macro that would allow me to highlight the two columns with the start date and end date and then have the adjacent (empty) column to the right populated with the newly formatted date. I envision either a temporary array or simply temporarily adding the same helper columns I populate with my functions above and then deleting them before the macro terminates.
I searched previous "date" posts but didn't find anything on point. Any assistance would be appreciated. Hopefully, my legwork makes this relatively easy for someone familiar with VBA.