我真的很困惑和好奇,为什么相同的编码,只是数据量不同,输出会完全不同?
With Sheets("control deck").Range("A2:A5000").SpecialCells(xlCellTypeBlanks)
.FormulaR1C1 = "=r[-1]C"
End With
与
With Sheets("control deck").Range("A2:A50000").SpecialCells(xlCellTypeBlanks)
.FormulaR1C1 = "=r[-1]C"
End With
第一个输出,仅使用上面单元格值的副本填充空白 第二个编码,用第一个单元格值的副本填充所有范围
我的数据:
> 1111 | abc |x
> |y
> |z
>
> 1112 | def |R
> |S
> |T
> |U
我希望得到什么
1111 | abc |x 1111 abc |y 1111 abc |z 1112 | def |R 1112 def |S 1112 def |T 1112 def |U
结果
> 1111 | abc |x > 1111 abc |y > 1111 abc |z > > 1111 | abc |R > 1111 abc |S > 1111 abc |T > 1111 abc |U
有人知道为什么吗?
只有当范围超过 30000 `row
时才会发生这种情况最佳答案
如果您使用的是 Excel 2007 或更早版本,SpecialCells
可以引用的不同单元格区域的数量有 8192 个限制
作为替代方案,请尝试此
Sub Demo()
Dim r As Range
Dim dat As Variant
Dim i As Long
Set r = Sheets("Sheet2").Range("A2:A50000")
dat = r.FormulaR1C1
For i = 1 To UBound(dat, 1)
If dat(i, 1) = "" Then
dat(i, 1) = "=r[-1]C"
End If
Next
r = dat
End Sub
这也会快得多。
关于vba - SpecialCells 根据范围大小返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20740604/