Extract Date & Year

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have the following code to extract the current month - 1 month as well as the year


Code:
 .body = "Attached please find Sales Data by region as at " & Format(Month(Date) - 1 & " " & Year(Date), "mmm yyyy") & " vs the Prior Year" & vbNewLine & vbNewLine



I would like this amended to extract the last date and year from row 1 on sheet "Sales Summary"

for eg a1 oct 2017, B1 Nov 2017, C1 Dec 2017

As Dec 2017 is the last row in row 1 containing a date and year , I would like Dec 2017 in this example to be extracted . If the last date was Jan 2018, then Jan 2018 in tow 1 to be extracted


it would be appreciated if someone could kindly amend my code
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Not knowing how your data is formatted, I have developed this code assuming your dates are in standard date form
Code:
Option Explicit


Sub lastDate()
Dim lc As Long
lc = Sheets("Sales Summary").Cells(1, Columns.Count).End(xlToLeft).Column
Dim LDate As Long
LDate = Cells(1, lc).Value
MsgBox ("Last Date is " & Format(LDate, "mm/dd/yyyy"))
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
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