Hello
@cjctmo.
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.
I give you the macro. You only have to make some adjustments in the macro, but it is very simple.
1. In these lines put the name of your sheets:
Rich (BB code):
Set sh1 = Sheets("Source") 'Fit to your sheet name
Set sh2 = Sheets("Output") 'Fit to your sheet name
2. As per your example the headers (ID, QUANT.,USE DATA, Date, Lot, Batch) in sheet1 are in row 2.
But if it is another line, change the 2 to the row number.
Rich (BB code):
lc = sh1.Cells(2, Columns.Count).End(1).Column
3. According to the above the data starts in cell A3, adjust if necessary.
Rich (BB code):
a = sh1.Range("A3", sh1.Cells(lr, lc)).Value
4. The output will start in cell C2, I guess it should be in column C for consistency with sheet1 and the other columns, like your example column H, adjust if necessary:
Rich (BB code):
sh2.Rows("2:" & Rows.Count).ClearContents
sh2.Range("C2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
Put the following macro in a module and run it.
VBA Code:
Sub identify_matches()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim a As Variant, b As Variant
Dim i As Long, j As Long, k As Long, m As Long, lr As Long, lc As Long
Set sh1 = Sheets("Source") 'Fit to your sheet name
Set sh2 = Sheets("Output") 'Fit to your sheet name
lr = sh1.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
lc = sh1.Cells(2, Columns.Count).End(1).Column
a = sh1.Range("A3", sh1.Cells(lr, lc)).Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
m = 1
For j = 3 To UBound(a, 2) Step 5
k = 0
For i = 1 To UBound(a, 1)
If a(i, j) = "Y" Then
k = k + 1
b(k, m) = a(i, 1)
End If
Next
m = m + 5
Next
sh2.Rows("2:" & Rows.Count).ClearContents
sh2.Range("C2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
End Sub
HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (identify_matches) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------