我對Excel vba相當新,但現在一直在使用access vba。根據列值複製工作表
我有一些代碼,拆分主文件到Excel中根據不同的列數其他文件
Sub SplitbyValue()
Dim FromR As Range, ToR As Range, All As Range, Header As Range
Dim Wb As Workbook
Dim Ws As Worksheet
'Get the header in this sheet
Set Header = Range("D8").EntireRow
'Visit each used cell in column D, except the header
Set FromR = Range("D9")
For Each ToR In Range(FromR, Range("D" & Rows.Count).End(xlUp).Offset(1))
'Did the value change?
If FromR <> ToR Then
'Yes, get the cells between
Set All = Range(FromR, ToR.Offset(-1)).EntireRow
'Make a new file
Set Wb = Workbooks.Add(xlWBATWorksheet)
'Copy the data into there
With Wb.ActiveSheet
Header.Copy .Range("A8")
All.Copy .Range("A9")
End With
'Save it
Wb.SaveAs ThisWorkbook.Path & "\" & Format(Date, "yyyy.mm.dd") & _
" - " & FromR.Value & ".xls", xlWorkbookNormal
Wb.Close
'Remember the start of this section
Set FromR = ToR
End If
Next
End Sub
這對於主片的偉大工程,但需要複製多個標籤,這僅僅獲取片。我如何擴展它,以便將其他工作表複製到該文件中?
例如: ColumnA Id1的 的Id2 ID3
這產生三個文件(ID1)(ID2)(ID3),但忽略了其他片材。
你需要一個'For Each(sheet variable)in(Workbook variable).Sheets'循環你的整個東西。現在只有當您啓動宏時,纔會啓用任何表格。 – puzzlepiece87