여러 개의 파일로 :VBA - 분할 Excel 워크 시트 나 Excel에서 다음 시트를
ID ND.T Time [s] Position X [%s] Position Y [%s] Speed [%s] Area [%s] Width [%s] MeanIntensity
1 1 3.87 417.57 11.46 0.06 339.48 14.1 245.65
1 2 8.72 417.37 11.68 0.04 342.61 14.15 239.34
1 3 13.39 417.57 11.66 0.04 344.17 14.3 239.48
2 1 3.87 439.01 6.59 0.02 342.61 11.66 204.47
2 2 8.72 438.97 6.65 0.007 342.61 10.7 197.96
2 3 13.39 438.94 6.66 0.03 345.74 11.03 214.74
나는 시간 [S] 열 (또는 ND.T 열)에 의해 파일에이 시트를 분리하려는
그래서 내가 가진이 별도의 파일
파일 : 3.87.xlxs
ID ND.T Time [s] Position X [%s] Position Y [%s] Speed [%s] Area [%s] Width [%s] MeanIntensity
1 1 3.87 417.57 11.46 0.06 339.48 14.1 245.65
2 1 3.87 439.01 6.59 0.02 342.61 11.66 204.47
파일 : 8.72.xlxs
ID ND.T Time [s] Position X [%s] Position Y [%s] Speed [%s] Area [%s] Width [%s] MeanIntensity
1 2 8.72 417.37 11.68 0.04 342.61 14.15 239.34
2 2 8.72 438.97 6.65 0.007 342.61 10.7 197.96
파일 : 나는 첫 번째 열에 고유 한 이름으로 파일을 분리 다음 VBA 코드를 발견 지금까지
ID ND.T Time [s] Position X [%s] Position Y [%s] Speed [%s] Area [%s] Width [%s] MeanIntensity
1 3 13.39 417.57 11.66 0.04 344.17 14.3 239.48
2 3 13.39 438.94 6.66 0.03 345.74 11.03 214.74
을 13.39.xlxs, 그래서 난 그냥이의 변형이 될 필요가 생각 :
는Option Explicit
Sub SplitIntoSeperateFiles()
Dim OutBook As Workbook
Dim DataSheet As Worksheet, OutSheet As Worksheet
Dim FilterRange As Range
Dim UniqueNames As New Collection
Dim LastRow As Long, LastCol As Long, _
NameCol As Long, Index As Long
Dim OutName As String
'set references and variables up-front for ease-of-use
Set DataSheet = ThisWorkbook.Worksheets("Sheet1")
NameCol = 1
LastRow = DataSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastCol = DataSheet.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Set FilterRange = Range(DataSheet.Cells(1, NameCol), DataSheet.Cells(LastRow, LastCol))
'loop through the name column and store unique names in a collection
For Index = 2 To LastRow
On Error Resume Next
UniqueNames.Add Item:=DataSheet.Cells(Index, NameCol), Key:=DataSheet.Cells(Index, NameCol)
On Error GoTo 0
Next Index
'iterate through the unique names collection, writing
'to new workbooks and saving as the group name .xls
Application.DisplayAlerts = False
For Index = 1 To UniqueNames.Count
Set OutBook = Workbooks.Add
Set OutSheet = OutBook.Sheets(1)
With FilterRange
.AutoFilter Field:=NameCol, Criteria1:=UniqueNames(Index)
.SpecialCells(xlCellTypeVisible).Copy OutSheet.Range("A1")
End With
OutName = ThisWorkbook.FullName
OutName = Left(OutName, InStrRev(OutName, "\"))
OutName = OutName & UniqueNames(Index)
OutBook.SaveAs Filename:=OutName, fileFormat:=xlExcel8
OutBook.Close SaveChanges:=False
Call ClearAllFilters(DataSheet)
Next Index
Application.DisplayAlerts = True
End Sub
'safely clear all the filters on data sheet
Sub ClearAllFilters(TargetSheet As Worksheet)
With TargetSheet
TargetSheet.AutoFilterMode = False
If .FilterMode Then
.ShowAllData
End If
End With
End Sub
아무 일도 일어나지 않으십니까? 당신이 단계를 거쳐야한다면 정확한 lastrow와 lastcol을 찾습니까? – Sun