shironokuro
New Member
- Joined
- Jul 17, 2024
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hello all,
Firstly I’m not that good in English so I’m sorry if my grammar is hard to understand.
my macro can get unique value in column “D” and split to each workbook by copy row that unique value was (example : in column D at row 1,5,7 is got same data so my macro will copy and place at new workbook).
for now I trying to hide column “B:G” after copy row to new workbook but it didn’t hide as I wish.
For Each value In uniqueValues ' Loop through each unique value and create a new workbook
Dim NewWs As Worksheet
Set newWorkbook = Workbooks.Add ' Create a new workbook for each unique value
Set NewWs = newWorkbook.Sheets(1)
' Filter and copy rows with the current unique value to new workbook
Set NewWs = newWorkbook.Sheets(1)
ws.Rows(1).Copy Destination:=newWorkbook.Sheets(1).Rows(1) ' Copy header row
For Each cell In rng
If cell.value = value Then
cell.EntireRow.Copy Destination:=newWorkbook.Sheets(1).Range("A" & newWorkbook.Sheets(1).Cells(newWorkbook.Sheets(1).Rows.Count, "A").End(xlUp).row + 1)
End If
Next cell
newWorkbook.Sheets(1).Columns("B:G").Hidden = True
fileName = value
newWorkbook.Sheets(1).Columns.AutoFit ' Autofit all columns in the worksheet
savePath = "C:\Users\" ' Adjust the path where you want to save the files
newWorkbook.SaveAs savePath & fileName ' Save the new workbook with the appropriate name and path
newWorkbook.Close SaveChanges:=False
Set newWorkbook = Nothing
Next value
Firstly I’m not that good in English so I’m sorry if my grammar is hard to understand.
my macro can get unique value in column “D” and split to each workbook by copy row that unique value was (example : in column D at row 1,5,7 is got same data so my macro will copy and place at new workbook).
for now I trying to hide column “B:G” after copy row to new workbook but it didn’t hide as I wish.
For Each value In uniqueValues ' Loop through each unique value and create a new workbook
Dim NewWs As Worksheet
Set newWorkbook = Workbooks.Add ' Create a new workbook for each unique value
Set NewWs = newWorkbook.Sheets(1)
' Filter and copy rows with the current unique value to new workbook
Set NewWs = newWorkbook.Sheets(1)
ws.Rows(1).Copy Destination:=newWorkbook.Sheets(1).Rows(1) ' Copy header row
For Each cell In rng
If cell.value = value Then
cell.EntireRow.Copy Destination:=newWorkbook.Sheets(1).Range("A" & newWorkbook.Sheets(1).Cells(newWorkbook.Sheets(1).Rows.Count, "A").End(xlUp).row + 1)
End If
Next cell
newWorkbook.Sheets(1).Columns("B:G").Hidden = True
fileName = value
newWorkbook.Sheets(1).Columns.AutoFit ' Autofit all columns in the worksheet
savePath = "C:\Users\" ' Adjust the path where you want to save the files
newWorkbook.SaveAs savePath & fileName ' Save the new workbook with the appropriate name and path
newWorkbook.Close SaveChanges:=False
Set newWorkbook = Nothing
Next value