我有一个代码,该代码将根据缩写复制一行并将其发送到从某个单元格开始的另一个excel工作表。我需要代码以不复制缩写词,而仅复制其余部分。我该如何修复我的代码。我需要排除的列是A列
表?数据
代码如下:
Private Sub CommandButton3_Click()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
j = 11 ' Start copying to row # in target sheet
For Each c In Source.Range("A1:A1000") ' range of the running log input
If c = "PP" Then
Source.Rows(c.Row).Copy Target.Rows(j) ' where i think problem is
j = j + 1 ' makes it paste to the next open row
End If
Next c
j = 30
For Each c In Source.Range("A1:A1000")
If c = "FA" Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
End Sub
答案 0 :(得分:2)
如果您知道要复制四个单元格,请尝试此操作。
Source.cells(c.Row,2).resize(,4).Copy Target.cells(j,1)
不确定为什么会有两个循环?自动过滤会更有效,因为您可以完全消除循环。