Find year

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000</SPAN></SPAN>
Hi,</SPAN></SPAN>

Data in column B:C</SPAN></SPAN>
Unique pattern in column E</SPAN></SPAN>
Count Patter in column F </SPAN></SPAN>

I need a solution to find year for the unique pattern result in column G:N</SPAN></SPAN>

Example</SPAN></SPAN> data</SPAN>


Book1
ABCDEFGHIJKLMN
1
2
3
4
5YearPattUnique PattCountYearYearYearYearYearYearYearYear
672/730 | 0 | 0 | 01 | 1 | 2 | 1
772/731 | 2 | 1 | 21 | 1 | 1 | 2
874/751 | 0 | 2 | 22 | 0 | 0 | 0
974/750 | 1 | 0 | 00 | 1 | 0 | 0474/7597/9897/9897/98
1074/751 | 1 | 1 | 11 | 1 | 1 | 1474/7576/7779/8079/80
1174/752 | 1 | 0 | 12 | 1 | 0 | 1674/7588/8999/0099/0099/0099/00
1276/770 | 0 | 0 | 22 | 0 | 1 | 2197/98
1376/771 | 2 | 0 | 01 | 2 | 0 | 0176/77
1476/771 | 1 | 1 | 12 | 1 | 1 | 0276/7795/96
1576/772 | 1 | 1 | 00 | 0 | 0 | 2276/7776/77
1676/770 | 0 | 0 | 22 | 1 | 1 | 2
1779/801 | 1 | 1 | 10 | 1 | 0 | 1388/8997/9899/00
1879/801 | 1 | 1 | 11 | 2 | 0 | 1279/8088/89
1979/801 | 1 | 1 | 00 | 1 | 1 | 1279/8099/00
2079/801 | 1 | 0 | 00 | 2 | 1 | 2
2179/801 | 2 | 0 | 10 | 0 | 0 | 0672/7379/8088/8995/9697/9897/98
2279/800 | 1 | 1 | 11 | 1 | 0 | 0579/8088/8997/9899/0099/00
2379/800 | 0 | 1 | 22 | 0 | 1 | 0188/89
2479/800 | 0 | 0 | 01 | 2 | 0 | 2188/89
2588/891 | 1 | 0 | 01 | 0 | 0 | 2
2688/890 | 1 | 0 | 11 | 0 | 1 | 0295/9699/00
2788/892 | 1 | 0 | 11 | 0 | 1 | 1295/9697/98
2888/892 | 0 | 1 | 02 | 0 | 1 | 1395/9697/9897/98
2988/891 | 2 | 0 | 11 | 2 | 1 | 0295/9695/96
3088/891 | 2 | 0 | 21 | 0 | 1 | 2195/96
3188/891 | 1 | 1 | 00 | 1 | 1 | 0697/9897/9899/0099/0099/0099/00
3288/890 | 1 | 2 | 10 | 0 | 1 | 2379/8097/9899/00
3388/890 | 0 | 0 | 00 | 2 | 1 | 0188/89
3495/961 | 0 | 0 | 11 | 1 | 0 | 2197/98
3595/961 | 0 | 1 | 01 | 1 | 0 | 1199/00
3695/961 | 0 | 1 | 10 | 0 | 0 | 1299/0099/00
3795/962 | 0 | 1 | 10 | 2 | 0 | 0
3895/961 | 2 | 1 | 01 | 2 | 1 | 2272/7399/00
3995/961 | 2 | 1 | 02 | 1 | 1 | 1199/00
4095/961 | 1 | 2 | 01 | 0 | 2 | 0199/00
4195/961 | 0 | 1 | 21 | 0 | 2 | 2174/75
4295/961 | 0 | 0 | 10 | 2 | 2 | 0199/00
4395/960 | 0 | 0 | 0
4495/962 | 1 | 1 | 0
4597/982 | 0 | 1 | 1
4697/980 | 0 | 0 | 0
4797/982 | 0 | 1 | 2
4897/980 | 1 | 1 | 0
4997/980 | 0 | 0 | 0
5097/980 | 1 | 0 | 0
5197/980 | 1 | 0 | 0
5297/980 | 0 | 1 | 2
5397/982 | 0 | 1 | 1
5497/981 | 1 | 0 | 0
5597/980 | 1 | 0 | 1
5697/981 | 0 | 1 | 1
5797/980 | 2 | 1 | 0
5897/981 | 1 | 0 | 2
5997/980 | 1 | 1 | 0
6097/980 | 1 | 0 | 0
6197/980 | 0 | 1 | 1
6299/000 | 0 | 1 | 1
6399/000 | 0 | 1 | 1
6499/000 | 0 | 0 | 1
6599/000 | 0 | 1 | 1
6699/001 | 1 | 0 | 0
6799/000 | 0 | 1 | 2
6899/000 | 0 | 1 | 1
6999/000 | 0 | 1 | 1
7099/001 | 0 | 1 | 0
7199/000 | 1 | 1 | 0
7299/000 | 1 | 1 | 0
7399/001 | 2 | 1 | 2
7499/002 | 1 | 1 | 1
7599/000 | 1 | 0 | 1
7699/001 | 0 | 2 | 0
7799/001 | 1 | 0 | 0
7899/000 | 1 | 1 | 1
7999/002 | 1 | 0 | 1
8099/002 | 1 | 0 | 1
8199/000 | 2 | 2 | 0
8299/000 | 1 | 1 | 0
8399/002 | 1 | 0 | 1
8499/001 | 1 | 1 | 0
8599/002 | 1 | 0 | 1
8699/001 | 0 | 0 | 0
8799/001 | 2 | 1 | 1
8899/001 | 1 | 0 | 1
8999/001 | 2 | 1 | 1
9099/002 | 0 | 2 | 1
9199/000 | 0 | 0 | 1
9299/000 | 1 | 1 | 0
93
94
Sheet1


Thank you in advance</SPAN></SPAN>

Regards,</SPAN>
Kishan</SPAN></SPAN>
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try:
This is an array formula and must be entered with CTRL-SHIFT-ENTER.
Drag formula across and down as needed.
Excel Workbook
ABCDEFGHIJKLMN
5YearPattUnique PattCountYearYearYearYearYearYearYearYear
672/730 | 0 | 0 | 01 | 1 | 2 | 1 
772/731 | 2 | 1 | 21 | 1 | 1 | 2
874/751 | 0 | 2 | 22 | 0 | 0 | 0
974/750 | 1 | 0 | 00 | 1 | 0 | 0474/7597/9897/9897/98
1074/751 | 1 | 1 | 11 | 1 | 1 | 1474/7576/7779/8079/80
1174/752 | 1 | 0 | 12 | 1 | 0 | 1674/7588/8999/0099/0099/0099/00
1276/770 | 0 | 0 | 22 | 0 | 1 | 2197/98
1376/771 | 2 | 0 | 01 | 2 | 0 | 0176/77
1476/771 | 1 | 1 | 12 | 1 | 1 | 0276/7795/96
1576/772 | 1 | 1 | 00 | 0 | 0 | 2276/7776/77
1676/770 | 0 | 0 | 22 | 1 | 1 | 2
1779/801 | 1 | 1 | 10 | 1 | 0 | 1388/8997/9899/00
1879/801 | 1 | 1 | 11 | 2 | 0 | 1279/8088/89
Sheet
 
Upvote 0
If you are looking for a VBA solution, give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub GetCountsAndDates()
  Dim R As Long, X As Long, Data As Variant, Patterns As Variant
  Dim YearPatt As Variant, Matches As Variant, Result As Variant
  Data = Range("B6", Cells(Rows.Count, "C").End(xlUp))
  Patterns = Range("E6", Cells(Rows.Count, "E").End(xlUp))
  ReDim YearPatt(1 To UBound(Data))
  For R = 1 To UBound(YearPatt)
    YearPatt(R) = Data(R, 1) & "X" & Data(R, 2)
  Next
  ReDim Result(1 To UBound(Data), 1 To 99)
  For R = 1 To UBound(Patterns)
    Matches = Filter(YearPatt, Patterns(R, 1))
    Result(R, 1) = 1 + UBound(Matches)
    For X = 0 To UBound(Matches)
      Result(R, 2 + X) = Split(Matches(X), "X")(0)
    Next
  Next
  Range("F6").Resize(UBound(Result, 1), UBound(Result, 2)) = Result
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Another VBA solution could be a user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy across and down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Code:
Function Find_Year(rData As Range, sPatt As String, Num As Long) As String
  On Error Resume Next
  Find_Year = Split(Filter(Application.Transpose(Evaluate(rData.Columns(1).Address & "&""@""&" & rData.Columns(2).Address)), sPatt)(Num - 1), "@")(0)
End Function

Excel Workbook
BCDEFGHIJKLMN
5YearPattUnique PattCountYearYearYearYearYearYearYearYear
672/730 | 0 | 0 | 01 | 1 | 2 | 1
772/731 | 2 | 1 | 21 | 1 | 1 | 2
874/751 | 0 | 2 | 22 | 0 | 0 | 0
974/750 | 1 | 0 | 00 | 1 | 0 | 0474/7597/9897/9897/98
1074/751 | 1 | 1 | 11 | 1 | 1 | 1474/7576/7779/8079/80
1174/752 | 1 | 0 | 12 | 1 | 0 | 1674/7588/8999/0099/0099/0099/00
1276/770 | 0 | 0 | 22 | 0 | 1 | 2197/98
1376/771 | 2 | 0 | 01 | 2 | 0 | 0176/77
1476/771 | 1 | 1 | 12 | 1 | 1 | 0276/7795/96
1576/772 | 1 | 1 | 00 | 0 | 0 | 2276/7776/77
1676/770 | 0 | 0 | 22 | 1 | 1 | 2
1779/801 | 1 | 1 | 10 | 1 | 0 | 1388/8997/9899/00
Sheet1
 
Upvote 0
Code:
Function Find_Year(rData As Range, sPatt As String, Num As Long) As String
  On Error Resume Next
  Find_Year = Split(Filter(Application.Transpose(Evaluate(rData.Columns(1).Address & "&""@""&" & rData.Columns(2).Address)), sPatt)(Num - 1), "@")(0)
End Function
The OP is using Excel 2000... does all of that work in his version (I wasn't sure)?
 
Last edited:
Upvote 0
.. does all of that work in his version (I wasn't sure)?
Absolutely no idea, that's why I said " .. solution could be .."
Same question would apply to your code, or any suggestions really, wouldn't it? This OP asks quite a few questions and I suspect not many, if any, of the people offering suggestions have a version that old to check. :cool: :eek:
 
Upvote 0
Try:
This is an array formula and must be entered with CTRL-SHIFT-ENTER.
Drag formula across and down as needed.

Spreadsheet Formulas
Cell
Formula
G6
{=IF(COLUMNS($G$5:G5)>$F6,"",INDEX($B$6:$B$92,SMALL(IF($E6=$C$6:$C$92,ROW($C$6:$C$92)-ROW($C$6)+1),COLUMNS($G$5:G5))))}

<TBODY>
</TBODY>

Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!


<TBODY>
</TBODY>
AhoyNC, your formula worked well<o:p></o:p>
<o:p></o:p>
Thank you for your help<o:p></o:p>
<o:p></o:p>
Kind Regards,
Kishan
 
Upvote 0
Another VBA solution could be a user-defined function. To implement ..

Spreadsheet Formulas
Cell
Formula
G9
=Find_Year($B$6:$C$92,$E9,COLUMNS($G9:G9))

<TBODY>
</TBODY>


<TBODY>
</TBODY>
Peter_SSs, yes Function worked perfectly </SPAN></SPAN>

Thank you for your help
</SPAN></SPAN>

Kind Regards,
</SPAN>
Kishan
</SPAN></SPAN>
 
Upvote 0
If you are looking for a VBA solution, give this macro a try...
Code:
[TABLE="width: 500"]
<TBODY>[TR]
[TD]Sub GetCountsAndDates()
  Dim R As Long, X As Long, Data As Variant, Patterns As Variant
  Dim YearPatt As Variant, Matches As Variant, Result As Variant
  Data = Range("B6", Cells(Rows.Count, "C").End(xlUp))
  Patterns = Range("E6", Cells(Rows.Count, "E").End(xlUp))
  ReDim YearPatt(1 To UBound(Data))
  For R = 1 To UBound(YearPatt)
    YearPatt(R) = Data(R, 1) & "X" & Data(R, 2)
  Next
  ReDim Result(1 To UBound(Data), 1 To 99)
  For R = 1 To UBound(Patterns)
    Matches = Filter(YearPatt, Patterns(R, 1))
    Result(R, 1) = 1 + UBound(Matches)
    For X = 0 To UBound(Matches)
      Result(R, 2 + X) = Split(Matches(X), "X")(0)
    Next
  Next
  Range("F6").Resize(UBound(Result, 1), UBound(Result, 2)) = Result
End Sub
[/TD]
[/TR]
</TBODY>[/TABLE]
Rick Rothstein, nice one it counts the patterns and search the year and finally live the values I liked your complete VBA one touch solution.</SPAN></SPAN>

Thank you very much for your help
</SPAN></SPAN>

Kind Regards,
</SPAN>
Kishan
</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,956
Members
449,096
Latest member
Anshu121

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