Hi all,
I have been struggling to develop a VBA process that identifies unique values within one column of a single worksheet, within a workbook with multiple worksheets. I want the process to create a new workbook for each unique value with all of the same worksheets, but within the worksheet with the unique value, I just want those values and not the entire selection of values to show up within the new worksheet/workbook. This should loop through all unique values within that column. Below are the two Subs I've created, Sub createDataTab() copies the master data tab so I don't delete data from it, and Sub createWorkbook() should loop through all the unique data variables in column C of the "Data_Tab" worksheet. I can further explain as the thread goes along, but any ideas would be great. Thanks.
Sub createDataTab()
For Each ws In Worksheets
If ws.Name = "Data_Test" Then
Application.DisplayAlerts = False
Sheets("Data_Test").Delete
Application.DisplayAlerts = True
Sheets("Data").Copy after:=Sheets("UserForm")
ActiveSheet.Name = "Data_Test"
End
End If
Next
End Sub
Sub createWorkbook()
cell = ActiveWorkbook.Worksheets("Scorecard-Raw").Range("C2").Value
Fpath = "C:\Users\rcherry1\Desktop\Macro Project_Peter\Itemized Categories"
Fname = Fpath & cell & ".xlsm"
Do Until IsEmpty(ActiveWorkbook.Worksheets("Data_Test").Range("C2").Value)
ActiveWorkbook.Worksheets("Data_Test").Select
Range("A2:AZ2").Select
Selection.Copy
ActiveWorkbook.Worksheets("Scorecard-Raw").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
For Each cell In Sheets("Data_Test").Range("C:C")
If cell.Value = Worksheets("Scorecard-Raw").Range("C2") Then
Application.DisplayAlerts = False
matchRow = cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Resize(1, 52).Cut
Sheets("Scorecard-Raw").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Sheets("Data_Test").Select
Application.DisplayAlerts = True
End If
Next
ActiveWorkbook.Worksheets("Scorecard-Raw").Select
Range("C2:C5000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveWorkbook.Worksheets("Data_Test").Select
Range("A2:BH2").Delete
Range("C2:C5000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveWorkbook.SaveCopyAs Filename:=Fname
ActiveWorkbook.Worksheets("Scorecard-Master").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Scorecard-Raw").Select
Cells.Select
ActiveSheet.Paste
Loop
End Sub
I have been struggling to develop a VBA process that identifies unique values within one column of a single worksheet, within a workbook with multiple worksheets. I want the process to create a new workbook for each unique value with all of the same worksheets, but within the worksheet with the unique value, I just want those values and not the entire selection of values to show up within the new worksheet/workbook. This should loop through all unique values within that column. Below are the two Subs I've created, Sub createDataTab() copies the master data tab so I don't delete data from it, and Sub createWorkbook() should loop through all the unique data variables in column C of the "Data_Tab" worksheet. I can further explain as the thread goes along, but any ideas would be great. Thanks.
Sub createDataTab()
For Each ws In Worksheets
If ws.Name = "Data_Test" Then
Application.DisplayAlerts = False
Sheets("Data_Test").Delete
Application.DisplayAlerts = True
Sheets("Data").Copy after:=Sheets("UserForm")
ActiveSheet.Name = "Data_Test"
End
End If
Next
End Sub
Sub createWorkbook()
cell = ActiveWorkbook.Worksheets("Scorecard-Raw").Range("C2").Value
Fpath = "C:\Users\rcherry1\Desktop\Macro Project_Peter\Itemized Categories"
Fname = Fpath & cell & ".xlsm"
Do Until IsEmpty(ActiveWorkbook.Worksheets("Data_Test").Range("C2").Value)
ActiveWorkbook.Worksheets("Data_Test").Select
Range("A2:AZ2").Select
Selection.Copy
ActiveWorkbook.Worksheets("Scorecard-Raw").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
For Each cell In Sheets("Data_Test").Range("C:C")
If cell.Value = Worksheets("Scorecard-Raw").Range("C2") Then
Application.DisplayAlerts = False
matchRow = cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Resize(1, 52).Cut
Sheets("Scorecard-Raw").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Sheets("Data_Test").Select
Application.DisplayAlerts = True
End If
Next
ActiveWorkbook.Worksheets("Scorecard-Raw").Select
Range("C2:C5000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveWorkbook.Worksheets("Data_Test").Select
Range("A2:BH2").Delete
Range("C2:C5000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveWorkbook.SaveCopyAs Filename:=Fname
ActiveWorkbook.Worksheets("Scorecard-Master").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Scorecard-Raw").Select
Cells.Select
ActiveSheet.Paste
Loop
End Sub