【发布时间】:2018-05-21 08:17:45
【问题描述】:
如果 DA 列中的单元格包含特定值,我想创建一个复制行范围的宏。
例如:
如果列 DA10 包含值 3-incompletion,N10 不包含任何内容,CI10 不包含任何内容 - 那么宏应将单元格 F10、H10 和 DA10 复制到工作簿 reportWB强>。我不知道该怎么做。
到目前为止的进展(感谢 Shai - 我仍然愚蠢地让它发挥作用):
Sub insertINCOMPLETION()
Dim dataWB As Workbook
Dim reportWB As Workbook
Dim workB As Workbook
Dim incomplRNG As Range
Dim LastRow6 As Long
Dim LastRow7 As Long
For Each workB In Application.Workbooks
If Left(workB.Name, 5) = "15B2" Then
Set dataWB = workB
Exit For
End If
Next
If Not dataWB Is Nothing Then
Set reportWB = ThisWorkbook
With reportWB.Sheets("getDATA")
LastRow6 = .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Row
End With
With dataWB.Sheets("Data")
LastRow7 = .Cells(.Rows.Count, "F").End(xlUp).Row
If InStr(.Range("DA" & LastRow7).Value2, "3-Incompletion") > 0 And _
Trim(.Range("N" & LastRow7).Value2) = "" And _
Trim(.Range("CI" & LastRow7).Value2) = "" Then
Set incomplRNG = Application.Union(.Range("F8:F" & LastRow7), .Range("H8:H" & LastRow7), .Range("DA8:DA" & LastRow7))
incomplRNG.Copy
reportWB.Sheets("getDATA").Range("B" & LastRow6).PasteSpecial xlPasteValues
End If
End With
End If
End Sub
还是不行。检查 DA 列后结束。
【问题讨论】:
-
将单元格与
"3-incompletion"进行比较的代码部分在哪里?你可以使用If InStr(.Cells(10, "AD"), "3-incompletion") > 0 Then -
我并不是很喜欢“如果”——之前尝试对数据进行排序,只复制排序后的区域,但因为它不起作用而尴尬地发布它......我会看看我是否可以实施你的建议。另外:感谢您编辑我所有的帖子。每次我提交问题时,我都认为您不必编辑它:-D - 2 分钟后...