问题
Model Place
model23 35372
model23 35372
model54 31034
model24 31034
model54 31034
model24 31034
I Have this Excel data (the data is bigger is 38000 lines+ I can add all here) I want try 2 paths..
1)Split the sheets by name model (but I want take and name model and place.
Example:
SheetName: model23
Model Place
model23 35372
model23 35372
2)If I can take a range for place value from x to y number and split then sheet to this range (example: 30000-40000).
With green box i want take values and add to a new sheet with model or better if i can make a new Excel file
回答1:
Try the following, your data will be split into new Excel Workbooks
New workbooks will be saved at CurPath = ActiveWorkbook.Path & "\"
Option Explicit
Private Sub Split_Data_NewBooks()
Dim Rng As Range
Dim List As Collection
Dim ListValue As Variant
Dim i As Long
Dim CurPath As String
CurPath = ActiveWorkbook.Path & "\"
' Set the Sheet Name
With ThisWorkbook.Sheets("Sheet1")
If .AutoFilterMode = False Then
Range("A1").AutoFilter
End If
Set Rng = Range(.AutoFilter.Range.Columns(1).Address)
Set List = New Collection
On Error Resume Next
For i = 2 To Rng.Rows.Count
List.Add Rng.Cells(i, 1), CStr(Rng.Cells(i, 1))
Next i
On Error GoTo 0
For Each ListValue In List
Rng.AutoFilter Field:=1, Criteria1:=ListValue
' // Copy the AutoFiltered Range to new Workbook
.AutoFilter.Range.Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:=CurPath & Left(ListValue, 30)
Cells.EntireColumn.AutoFit
ActiveWorkbook.Close savechanges:=True
Next ListValue
.AutoFilter.ShowAllData
.AutoFilterMode = False
.Activate
End With
End Sub
回答2:
Depending on your reasons for doing this, I would suggest this outcome would not be desirable.
Generally a workbook with too many worksheets is not very functional.
For anyone other than the author of the spreadsheet its far to hard to find what you need.
Not sure what purpose you are doing this for but there will almost certainly be a better design you can implement.
That being said its certainly possible as 0m3r has linked you.
来源:https://stackoverflow.com/questions/43908597/excel-split-sheet-data-by-name-into-new-excel-workbook