Extract Date from Last Number

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
1,811
Office Version
  1. 2013
Platform
  1. Windows
hi all..
how to extract or pull number from last date number
note use vba/macro
Book1
FG
2date (dd-mm-yyyy)extract number
323/10/20200
409/12/20166
501/01/20177
623/10/19955
Sheet1


thank in advance
.sst
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,883
Office Version
  1. 365
Platform
  1. Windows
Are you saying you want a macro for this, rather than a simple formula?
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
423
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi, using formula:

Queries-2.xlsm
AB
1date (dd-mm-yyyy)extract number
223-10-20200
309-12-20166
401-01-20177
523-10-19955
6
Sheet1
Cell Formulas
RangeFormula
B2:B5B2=RIGHT(YEAR(A2),1)
 
Solution

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
423
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Using Macro:
VBA Code:
Sub showLastDigit()
   With Sheets("Sheet1")
    For rowno = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
        .Cells(rowno, 3) = Right(Year(.Cells(rowno, 1)), 1)
    Next
End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,883
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Another option without the loop
VBA Code:
Sub muhammad()
   With Range("G3:G" & Range("F" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate("if({1},right(year(" & .Offset(, -1).Address & ")))")
   End With
End Sub
 

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
1,811
Office Version
  1. 2013
Platform
  1. Windows
hi Saurabhj & Fluff ...thank you very much..
all that worked great!!
sorry i missing it :
note use macro should be don't use...
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,883
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
423
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Thanks for the feedback, Muhammad.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,172
Messages
5,640,584
Members
417,152
Latest member
DayTimeSeby

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
Top