我有一系列不连续的单元格,我想将它们从一张纸 (wseDNA1) 复制到第二张纸 (wsElog1)。我只想在 wseDNA1 中的值不是“NR”并且 wsElog1 中的单元格尚未包含值时进行复制。 我想做一个循环,但不知道如何在不查看每个单元格(而不仅仅是我想要复制的单元格)的情况下执行此操作。下面是没有条件规则的复制范围的示例。我每天都会有一百多个这样的地图来绘制。
wsElog1.Range("BP" & RowNum) = wseDNA1.Range("AE12")
wsElog1.Range("BQ" & RowNum) = wseDNA1.Range("AG12")
wsElog1.Range("BN" & RowNum) = wseDNA1.Range("AO12")
wsElog1.Range("BR" & RowNum) = wseDNA1.Range("AQ12")
wsElog1.Range("BS" & RowNum) = wseDNA1.Range("AS12") ```
Sub Test()
' Make sure these two have the same number of elements
' and that they are correctly associated.
Dim eCols() As Variant: eCols = VBA.Array("BP", "BQ", "BN", "BR", "BS")
Dim dCols() As Variant: dCols = VBA.Array("AE", "AG", "AO", "AQ", "AS")
Dim nUpper As Long: nUpper = UBound(eCols)
Dim RowNum As Long, n As Long, eStr As String, dStr As String
For RowNum = 2 To 3 ' adjust!
For n = 0 To nUpper
eStr = CStr(wsElog1.Cells(RowNum, eCols(n)).Value)
If Len(eStr) > 0 Then
dStr = CStr(wsDNA1.Cells(RowNum, dCols(n)).Value)
If StrComp(dStr, "NR", vbTextCompare) <> 0 Then
wsElog1.Cells(RowNum, eCols(n)).Value _
= wsDNA1.Cells(12, dCols(n)).Value
End If
End If
Next n
Next RowNum
End Sub