I'm using the below code, I'm scanning column B against a set of critera (Array) if the cell has one of the values, copy the row, then take the row to the employee name (Column A) and put the row on the next line down, should there be no sheet for the employee make a new one.
The code at the moment is getting to the second line (Same Employee name) and choosing to try and make a new sheet rather than add to the existing one.
This is causing an error as it cant make another sheet of the same name.
`Sub Sample()
Dim myarray
Dim wsInv As Worksheet, wsDes As Worksheet
Dim rngDes As Range, rngEmp As Range, cel As Range
Set wsInv = ThisWorkbook.Sheets("Inventory")
Set rngEmp = wsInv.Range("A2", wsInv.Range("A" & Rows.Count).End(xlUp).Address)
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")
For Each cel In rngEmp
If Not IsError(Application.Match(cel.Offset(0, 1).Value, myarray, 0)) Then
On Error Resume Next
Set wsDes = ThisWorkbook.Sheets(cel.Value)
On Error GoTo 0
'Error is here vvvvv
If wsDes Is Nothing Then Set wsDes = ThisWorkbook.Sheets.Add(after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
'It should just move on but doesnt
wsDes.Name = cel.Value
cel(1 - (cel.Row - 1)).EntireRow.Copy wsDes.Range("A1")
cel.EntireRow.Copy wsDes.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Set wsDes = Nothing
End If
Next cel
End Sub`
Help? please!
In order for wsDes to have a value it is to equal
ThisWorkbook.Sheets(cel.Value)
When i highlight this line, it tells me
ThisWorkbook.Sheets(cel.Value) = <Subscript out of range>
This would give the nothing value to make a new sheet, thoughts??
cel(1 - (cel.Row - 1)).into something that involesrows.count?