I have the below code that will look in column B and determine if the row should be copied to a new cell or if it should move to the next row down, based on the conditions. What I want it to do is to first look in column A, employee names, and if the name in say row k is not the same as in row k-1, then make a new sheet, copy row k to there and then loop around. Eventually, every employee has their own sheet.
Sub Sample()
Dim myarray
Dim wsInv As Worksheet
Dim rngDes As Range, rng As Range, cel As Range
Dim k As Long
Set wsInv = Thisworkbook.Sheets("Inventory")
Set rng = wsInv.Range("A2", wsInv.Range("A" & Rows.Count).End(xlup).Address)
Set rngDes = Thisworkbook.Sheets("Sheet3").Range("A3")
myarray = Array("CONSUMABLES", "FILTERS - BILLI TRIO", "FILTERS - ZIP GENERIC", _
"GOODS", "HARDWARE FIXINGS", "LIGHTING - 50W DICHROIC", "LIGHTING - COMPACT BC/ES", _
"LIGHTING - DICHROIC LAMP", "LIGHTING - FLURO", "LIGHTING - PLC LAMP 840/830", _
"LIGHTING - PL-L", "LIGHTING - PULSE STARTER", "LIGHTING - STANDARD STARTER", _
"LIGHTING - T5 FLURO", "NITROGEN CHARGE", "OXYGEN / ACETYLENE WELDING", _
"R-134A", "R-22", "R-407C", "R-410A")
k = 0
For Each cel in rng
If cel.Value = cel.Offset(-1,0).Value Then
If Not IsError(Application.Match(cel.Offset(0,1).value, myarray, 0)) Then
cel.EntireRow.Copy rngDes.Offset(k,0)
k = k + 1
End If
End If
Next cel`
If anyone could at least tell me where I can get to a new sheet based on column A value, that would be amazing, thank you
So if I read this right, then you want to have column A with employees, column B with something that you want to use to compare, and column C with inventory type. If that's the case, and if this table is sorted on the employees column, then the following modification to what you have should do the trick.
If you can't sort by employees...then it is a little bit trickier. You'd have to add a function that searches through the sheet names to see if that sheet already exists, then find where you left off on that sheet, and then paste there. Its going to make your life a lot easier if you can sort.
As commented, try this:
What above code does is check if value in
Column B
is within the array.If yes, it will copy data to a
Sheet
named after the employee.If that employee don't have an existing
Sheet
yet, it will create one.Not sure if this helps, but give it a try.