我是编程新手,也是自学成才,所以请原谅我的无知和错误。我正在尝试编写一个宏来查找列F行1到1000(F1:F1000)中的非空单元格,然后(如果存在数据)在值下面插入一行,然后从F到J的列中删除值将值从A列粘贴到新创建的行中。然后,它将转到F列中的下一个非空单元格并重复。一旦用F列完成,它将转到列K行1到1000,如果存在数据,则在该值下面插入一行,然后从dolumn K中删除值,并将值从A列粘贴到新创建的行中E.它将通过列IP重复(在列IE中查找内容,在下面插入行并将值从IE切换到IP并粘贴到A:E。
我的代码如下。任何帮助将不胜感激。
Sub JW_Barcode()
Application.Calculation = xlCalculationManual
Dim rng As Range
For Each rng In Range("F1:F1000")
If rng.Value <> "" Then
rng.Offset(1, 0).EntireRow.Insert
End If
Next
Dim a As Integer
For a = 1 To 1000
On Error GoTo NextColumn
With Columns("F:J")
.Find(what:="*", after:=.Cells(1, 1), LookIn:=xlValues).Activate
End With
Selection.Cut
With Columns("A:E")
.Find(what:="", after:=.Cells(1, 1), LookIn:=xlValues).Activate
End With
ActiveSheet.Paste
Next a
NextColumn:
Dim rng2 As Range
For Each rng2 In Range("K1:K1000")
If rng2.Value <> "" Then
rng2.Offset(2, 0).EntireRow.Insert
End If
Next
Dim b As Integer
For b = 1 To 1000
On Error GoTo NextColumn2
With Columns("K:O")
.Find(what:="*", after:=.Cells(1, 1), LookIn:=xlValues).Activate
End With
Selection.Cut
With Columns("A:E")
.Find(what:="", after:=.Cells(1, 1), LookIn:=xlValues).Activate
End With
ActiveSheet.Paste
Next b
NextColumn2:
等......直到它在列IE中找到值,切割IE:IP并在新创建的行中粘贴A:E。