EM có 1 file dữ liệu > 1.000 dòng đang cần isert khoảng 30 dòng trắng giữa các dòng dữ liệu có sẵn , các bác có cách nào giúp em với ?
Sub newex()
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayAlerts = False
End With
Dim i As Integer
Dim j As Integer
For j = 2000 To 2 Step -1
For i = 1 To 30
Rows(j).Insert
Next
Next
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Bạn tham khảo cái này nhé
PHP:Sub newex() With Application .Calculation = xlCalculationManual .ScreenUpdating = False .DisplayAlerts = False End With Dim i As Integer Dim j As Integer For j = 2000 To 2 Step -1 For i = 1 To 30 Rows(j).Insert Next Next With Application .Calculation = xlCalculationAutomatic .ScreenUpdating = True .DisplayAlerts = True End With End Sub
- Bạn xem File đính kèm nhé
2000 thay bằng counta(vùng)
Sub newex()
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayAlerts = False
End With
Dim i As Integer, d As Long
Dim j As Integer
d = Application.WorksheetFunction.CountA(Sheet1.Range("A1:A2000"))
For j = d To 2 Step -1
For i = 1 To 30
Rows(j).Insert
Next
Next
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Dự là code này sẽ chạy lâu bà cố...........
để giới hạn lại khi vòng lặp for next sẽ cải thiện tốc độ
Sub newex()
Dim lr As Long
lr = Range("A" & Rows.Count).End(3).Row
Rows(Int(lr / 2) + 1 & ":" & Int(lr / 2) + 30).EntireRow.Insert
End Sub
Sub newex()
Dim lr As Long, i
lr = Range("A" & Rows.Count).End(3).Row
For i = lr To 2 Step -1
Rows(i & ":" & i + 29).EntireRow.Insert
Next
End Sub
Option Explicit
Sub Insert30RowsIn1000Rows()
Dim J As Byte, Tmp As Integer, BD As Integer
Randomize: BD = 999
For J = 1 To 30
Tmp = 30 * Rnd() \ 1
Rows(BD - Tmp & ":" & BD - Tmp).Insert
BD = BD - Tmp
Next J
End Sub
DIỄN ĐÀN GIẢI PHÁP EXCEL Group 1
DIỄN ĐÀN GIẢI PHÁP EXCEL Group 2