我试图使范围(单元格(1,1),单元格(10,1)在范围AAA中具有值,当值在AAA中为空时,它显示范围BBB中的值。但是我得到的结果是在给定的范围内只有范围BBB。
例如:
- 当AAA(1) = 12345时,Cells(1,1) = 12345
- 当AAA(2) =空时,Cells(2,1) = BBB(2) = 54321
With Activesheet
Range(cells(1,1), cells(10,1) = AAA
If Range(cells(1,1), cells(10,1) = "" Then
Range(cells(1,1), cells(10,1) = BBB
End if
End With
迭代AAA
并将空白替换为BBB
中的相应值,然后应用数组:
Dim i As Long
For i = LBound(AAA, 1) To UBound(AAA, 1)
If AAA(i, 1) = "" Then AAA(i, 1) = BBB(i, 1)
Next i
With ActiveSheet
.Range(.Cells(1, 1), .Cells(10, 1)) = AAA
End With
如果您不想修改AAA
,那么创建第三个Array并使用它作为输出:
Dim CCC As Variant
CCC = AAA
Dim i As Long
For i = LBound(AAA, 1) To UBound(AAA, 1)
If AAA(i, 1) = "" Then CCC(i, 1) = BBB(i, 1)
Next i
With ActiveSheet
.Range(.Cells(1, 1), .Cells(10, 1)) = CCC
End With