snuffnchess
Board Regular
- Joined
- May 15, 2015
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hello Excel Wizards
I am needing help on two things.
First:
The below code is working to essentially copy data that would exist from filters to a new worksheet, and then save that worksheet. It may be clunky... but it works.
Right now, if there is no data that appears in the filtered range, a workbook is created with just the header row. (So there are 4 files created for each value in Frandata.range("A" & Y) - but in some cases there may only need to be 1 file created.)
What I am wanting to do, though, is make it so that if the filtered range does not show data, that it just moves on to the next set of data to filter.
Secondly:
Other than attaching a variable to the "ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5))" range... is there anything else that I could do to optimize this part of the code?
I am needing help on two things.
First:
The below code is working to essentially copy data that would exist from filters to a new worksheet, and then save that worksheet. It may be clunky... but it works.
Right now, if there is no data that appears in the filtered range, a workbook is created with just the header row. (So there are 4 files created for each value in Frandata.range("A" & Y) - but in some cases there may only need to be 1 file created.)
What I am wanting to do, though, is make it so that if the filtered range does not show data, that it just moves on to the next set of data to filter.
Secondly:
Other than attaching a variable to the "ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5))" range... is there anything else that I could do to optimize this part of the code?
VBA Code:
For y = 1 To frandatalrow
Set nb = Workbooks.Add
Set ns = nb.Worksheets(1)
ardata.Activate
Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=1, Criteria1:=frandata.Range("A" & y).Value
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=11, Criteria1:="DA"
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=9, Criteria1:="ccauto"
ardata.Range(Cells(1, 2), Cells(arlrow, 8)).SpecialCells(xlCellTypeVisible).Copy
ns.Cells(1, 1).PasteSpecial xlPasteAll
ns.Columns.AutoFit
sFilename = frandata.Range("A" & y).Value
nb.SaveAs sfolca & "CC Auto\" & sFilename & ".xlsx", 51
nb.Close False
ardata.ShowAllData
Set nb = Workbooks.Add
Set ns = nb.Worksheets(1)
ardata.Activate
Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=1, Criteria1:=frandata.Range("A" & y).Value
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=11, Criteria1:="DA"
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=9, Criteria1:="ccman"
ardata.Range(Cells(1, 2), Cells(arlrow, 8)).SpecialCells(xlCellTypeVisible).Copy
ns.Cells(1, 1).PasteSpecial xlPasteAll
ns.Columns.AutoFit
sFilename = frandata.Range("A" & y).Value
nb.SaveAs sfolca & "CC Manual\" & sFilename & ".xlsx", 51
nb.Close False
ardata.ShowAllData
Set nb = Workbooks.Add
Set ns = nb.Worksheets(1)
ardata.Activate
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=1, Criteria1:=frandata.Range("A" & y).Value
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=11, Criteria1:="HE"
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=9, Criteria1:="achauto"
ardata.Range(Cells(1, 2), Cells(arlrow, 8)).SpecialCells(xlCellTypeVisible).Copy
ns.Cells(1, 1).PasteSpecial xlPasteAll
ns.Columns.AutoFit
sFilename = frandata.Range("A" & y).Value
nb.SaveAs sfolca & "ACH Manual\" & sFilename & ".xlsx", 51
nb.Close False
ardata.ShowAllData
Set nb = Workbooks.Add
Set ns = nb.Worksheets(1)
ardata.Activate
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=1, Criteria1:=frandata.Range("A" & y).Value
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=11, Criteria1:="HE"
ardata.Range(Cells(1, 1), Cells(arlrow, arlcol + 5)).AutoFilter Field:=9, Criteria1:="achman"
ardata.Range(Cells(1, 2), Cells(arlrow, 8)).SpecialCells(xlCellTypeVisible).Copy
ns.Cells(1, 1).PasteSpecial xlPasteAll
ns.Columns.AutoFit
sFilename = frandata.Range("A" & y).Value
nb.SaveAs sfolca & "ACH Manual\" & sFilename & ".xlsx", 51
nb.Close False
ardata.ShowAllData
Next y