vba - VBA-复制没有特定列的行
问题描述
我有一个代码,它将根据缩写复制一行并将其发送到从某个单元格开始的另一个 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
解决方案
如果您知道要复制四个单元格,请尝试此操作。
Source.cells(c.Row,2).resize(,4).Copy Target.cells(j,1)
不知道为什么你有两个循环?自动过滤器会更有效,因为您可以完全取消循环。
推荐阅读
- debugging - 调试器在启动他们的被调试者时如何绕过图像文件执行选项?
- ghost-blog - Ghost API 未添加帖子正文
- javafx - 使用自定义 asString 方法将 simpleStringProperty 绑定到 simpleIntegerProperty
- reactjs - 如何为响应中的搜索编写单元测试用例
- c - 无法在 C 中编译 Windows Socket
- laravel - Axios调用后Laravel Vue js响应结果未更新
- javascript - 从 Mongoose 数组中过滤结果并填充 objectId 的子字段
- javascript - NodeJS:循环内的中止请求函数
- javascript - 滚动时不能将一个 div 粘贴在另一个 div 下
- mysql - MySQL 8 的这种语法有什么问题?,它在 5.7 上运行良好