As shown in the image, I had the raw data (A2:C6) and I want to create a new workbook based on each unique value in columns B. In the example, there are 4 colors in the "Color" column and 3 unique colors, so I would create 3 different new workbooks (Red.xlsx, Yellow.xlsx, and Orange.xlsx) as shown in the bottom part of the image.
So the code I have in mind is as below but not sure how to check if the workbook has already been created:
Sub Move()
lr = [a1].CurrentRegion.Rows.Count
For each color in Range("B3:B" & lr)
Workbooks.Add.SaveAs FileName:= color
Workbooks("raw.xlsx").Activate
With [a1].CurrentRegion
.AutoFilter 2, color
.Copy Workbooks(color).Sheets(1).[a1]
.AutoFilter
End With
Workbooks(color).Close True
Next color
End Sub
The problem with my code is that it would create duplicated workbooks such as the Red.xlsx twice in the example. Any advice on how to fix the problem or a totally different approach of achieving the same result will be much appreciated!
