So this this the code i'm using to extract the data based on column B and putting it into new sheets named after Column B. I'd like to add code that says if the sheet exists, then paste on that sheet in next available row instead of adding a new sheet.
VBA Code:
Dim lastrow As Long, LastCol As Integer, i As Long, iStart As Long, iEnd As Long
Dim WS As Worksheet, r As Range, iCol As Integer, t As Date, Prefix As String
Dim sh As Worksheet, Master As String, Folder As String, Fname As String
On Error Resume Next
Set r = Sheet1.Range("B:B")
On Error GoTo 0
If r Is Nothing Then Exit Sub
iCol = r.Column
t = Now
With Sheet1
Master = .Name
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(3, Columns.Count).End(xlToLeft).Column
.Range(.Cells(3, 1), .Cells(lastrow, LastCol)).Sort Key1:=.Cells(3, 8), Order1:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range(.Cells(3, 1), .Cells(lastrow, LastCol)).Sort Key1:=.Cells(3, iCol), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
iStart = 4
For i = 4 To lastrow
If .Cells(i, iCol).Value <> .Cells(i + 1, iCol).Value Then
iEnd = i
Sheets.Add after:=Sheets(Sheets.Count)
Set WS = ActiveSheet
On Error Resume Next
WS.Name = .Cells(iStart, iCol).Value & "Fruit"
On Error GoTo 0
WS.Range(Cells(1, 1), Cells(1, LastCol)).Value = .Range(.Cells(3, 1), .Cells(3, LastCol)).Value
.Range(.Cells(iStart, 1), .Cells(iEnd, LastCol)).Copy Destination:=WS.Range("A2")
iStart = iEnd + 1
Cells.Select
Cells.EntireColumn.AutoFit
End If
Next i
End With