kiendaide1
Thành viên chính thức
- Tham gia
- 3/4/13
- Bài viết
- 93
- Được thích
- 4
Phiền anh sửa luôn vào lệnh gửi lại lệnh cho em xin với ạ. em cảm ơn anh.Kien đại để hay Kiên dài? Thích tên nick quá cơ.
Set RangeTieuDe = ThisSheet.Range("Vung tieu de")
For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile
Set wb = Workbooks.Add
RangeTieuDe.Copy wb.Sheets(1).Range("A1")
'...
RangeToCopy.Copy wb.Sheets(1).Range("A2")
Next p
Mình sửa thử theo gợi ý của bài #2, bạn tham khảo nhé :Phiền anh sửa luôn vào lệnh gửi lại lệnh cho em xin với ạ. em cảm ơn anh.
Sub Test()
Dim wb As Workbook
Dim ThisSheet As Worksheet
Dim NumOfColumns As Integer
Dim RangeTieuDe As Range
Dim RangeToCopy As Range
Dim WorkbookCounter As Integer
Dim RowsInFile
Dim Prefix As String
Application.ScreenUpdating = False
'Initialize data
Set ThisSheet = ThisWorkbook.ActiveSheet
Set RangeTieuDe = ThisSheet.Range("Vung tieu de")
NumOfColumns = ThisSheet.UsedRange.Columns.Count
WorkbookCounter = 1
RowsInFile = 500 'how many rows (incl. header) in new files?
Prefix = "test" 'prefix of the file name
For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile
Set wb = Workbooks.Add
RangeTieuDe.Copy wb.Sheets(1).Range("A1")
'Paste the chunk of rows for this file
Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + RowsInFile - 1, NumOfColumns))
RangeToCopy.Copy wb.Sheets(1).Range("A2")
'Save the new workbook, and close it
wb.SaveAs ThisWorkbook.Path & "\" & Prefix & "_" & WorkbookCounter
wb.Close
'Increment file counter
WorkbookCounter = WorkbookCounter + 1
Next p
Application.ScreenUpdating = True
Set wb = Nothing
End Sub
em cam ơn anh ạMình sửa thử theo gợi ý của bài #2, bạn tham khảo nhé :
PHP:Sub Test() Dim wb As Workbook Dim ThisSheet As Worksheet Dim NumOfColumns As Integer Dim RangeTieuDe As Range Dim RangeToCopy As Range Dim WorkbookCounter As Integer Dim RowsInFile Dim Prefix As String Application.ScreenUpdating = False 'Initialize data Set ThisSheet = ThisWorkbook.ActiveSheet Set RangeTieuDe = ThisSheet.Range("Vung tieu de") NumOfColumns = ThisSheet.UsedRange.Columns.Count WorkbookCounter = 1 RowsInFile = 500 'how many rows (incl. header) in new files? Prefix = "test" 'prefix of the file name For p = 1 To ThisSheet.UsedRange.Rows.Count Step RowsInFile Set wb = Workbooks.Add RangeTieuDe.Copy wb.Sheets(1).Range("A1") 'Paste the chunk of rows for this file Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + RowsInFile - 1, NumOfColumns)) RangeToCopy.Copy wb.Sheets(1).Range("A2") 'Save the new workbook, and close it wb.SaveAs ThisWorkbook.Path & "\" & Prefix & "_" & WorkbookCounter wb.Close 'Increment file counter WorkbookCounter = WorkbookCounter + 1 Next p Application.ScreenUpdating = True Set wb = Nothing End Sub