year of the date

mark692

Active Member
Joined
Feb 27, 2015
Messages
321
Office Version
  1. 2016
Platform
  1. Windows
i want to put a formula on column C that will show me the year of the given date on column A inside the same group code in column B, like this


Excel 2013/2016
ABC
1DateGroup CodeYear
203/17/201812018
312018
412018
503/06/201722016, 2017
601/01/201622016, 2017
722016, 2017
812/01/201732017
932017
Sheet1
 
Try Now please
Code:
Function GroupDates(GroupNum As Long) As String  Dim R As Long, Dates As Variant
  Dates = Range(Cells(1, "B"), Cells(Rows.Count, "B").End(xlUp))
  For R = UBound(Dates) To 1 Step -1
    If Cells(R, "B").Value = GroupNum And Cells(R, "A") <> "" Then
    MyYear = Year(Cells(R, "A").Value)
    If InStr(GroupDates, MyYear) = 0 Then GroupDates = GroupDates & ", " & MyYear
    End If
  Next
  GroupDates = Mid(GroupDates, 3)
  Application.Volatile
End Function
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try Now please
Code:
Function GroupDates(GroupNum As Long) As String  Dim R As Long, Dates As Variant
  Dates = Range(Cells(1, "B"), Cells(Rows.Count, "B").End(xlUp))
  For R = UBound(Dates) To 1 Step -1
    If Cells(R, "B").Value = GroupNum And Cells(R, "A") <> "" Then
    MyYear = Year(Cells(R, "A").Value)
    If InStr(GroupDates, MyYear) = 0 Then GroupDates = GroupDates & ", " & MyYear
    End If
  Next
  GroupDates = Mid(GroupDates, 3)
  Application.Volatile
End Function


hmm im confuse the first time i apply your code on my workbook it works but now its not.. hmmm
 
Upvote 0
i hope im not asking too much can you check the if i inserted the code properly?

http://www.mediafire.com/file/oce2933i3fibbin/Sales.xlsm


Column A= date
Column P= Group Code
Column S= is suppose to be where the year will appear

Module9= were you can find the code and i modified it a little to work on my worksheet at first it work i but now dont know what happened, its shows "#VALUE!" now

thanks for all your answer!
 
Upvote 0
i hope im not asking too much can you check the if i inserted the code properly?

http://www.mediafire.com/file/oce2933i3fibbin/Sales.xlsm


Column A= date
Column P= Group Code
Column S= is suppose to be where the year will appear

Module9= were you can find the code and i modified it a little to work on my worksheet at first it work i but now dont know what happened, its shows "#VALUE!" now
Try replacing the code you have in Module9 with this code...
Code:
[table="width: 500"]
[tr]
	[td]Function GroupDates(GroupNum As Long) As String
  Dim R As Long, Groups As Variant
  Groups = Range(Cells(1, "P"), Cells(Rows.Count, "P").End(xlUp))
  For R = UBound(Groups) To 6 Step -1
    If Cells(R, "P").Value = GroupNum And Cells(R, "A") <> "" Then
      If Not GroupDates & ", " Like "*" & Year(Cells(R, "A").Value) & "*" Then
        GroupDates = GroupDates & ", " & Year(Cells(R, "A").Value)
      End If
    End If
  Next
  GroupDates = Mid(GroupDates, 3)
End Function[/td]
[/tr]
[/table]
Then go to your "Collection Check" sheet and refresh it... once you do that, all of the values in Column S should correct themselves.
 
Upvote 0
Try replacing the code you have in Module9 with this code...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Function GroupDates(GroupNum As Long) As String
  Dim R As Long, Groups As Variant
  Groups = Range(Cells(1, "P"), Cells(Rows.Count, "P").End(xlUp))
  For R = UBound(Groups) To 6 Step -1
    If Cells(R, "P").Value = GroupNum And Cells(R, "A") <> "" Then
      If Not GroupDates & ", " Like "*" & Year(Cells(R, "A").Value) & "*" Then
        GroupDates = GroupDates & ", " & Year(Cells(R, "A").Value)
      End If
    End If
  Next
  GroupDates = Mid(GroupDates, 3)
End Function[/TD]
[/TR]
</tbody>[/TABLE]
Then go to your "Collection Check" sheet and refresh it... once you do that, all of the values in Column S should correct themselves.


thanks you so much sir, it works! :)
 
Upvote 0

Forum statistics

Threads
1,215,981
Messages
6,128,084
Members
449,418
Latest member
arm56

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