工作需要,需要把Excel按照固定行數(shù)拆分,生成多個Excel停蕉。
1.打開Excel,鼠標(biāo)不要任何選擇钙态。按“Alt”+“f11”慧起。
在sheet1貼上以下代碼,WJhangshu = 250 册倒,我們是按照250行來拆分一個的蚓挤。
Sub cfb()
Dim r, c, i, WJhangshu, WJshu, bt As Long
r = Range("A" & Rows.Count).End(xlUp).Row
c = Cells(1, Columns.Count).End(xlToLeft).Column
bt = 1 'title
WJhangshu = 250 'num
WJshu = IIf(r - bt Mod 20000, Int((r - bt) / WJhangshu), Int((r - bt) / WJhangshu) + 1)
For i = 0 To WJshu
Workbooks.Add
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & Format(i, String(Len(WJshu), 0)) & ".xlsx"
Application.DisplayAlerts = True
ThisWorkbook.ActiveSheet.Range("A1").Resize(bt, c).Copy ActiveSheet.Range("A1")
ThisWorkbook.ActiveSheet.Range("A" & bt + i * WJhangshu + 1).Resize(WJhangshu, c).Copy _
ActiveSheet.Range("A" & bt + 1)
ActiveWorkbook.Close True
Next
End Sub
2. 切回Excel,Alt+f8.彈出框選擇剛才的宏驻子,可以“執(zhí)行”或者單步執(zhí)行灿意。
3.核對數(shù)據(jù)