Excel中的SpecialCells返回公式的值 [英] SpecialCells in Excel to return value of a formula
问题描述
我想要一种快速简单的方法,使用Excel中的 SpecialCells
将单元格值复制到另一张工作表,而不是循环
I wanted a quick simple way to copy cell values to another sheet using SpecialCells
in Excel as opposed to looping
我的VBA代码如下:
Sub copyMissingData()
Worksheets("Source").Range("Z4:Z2000").SpecialCells(xlCellTypeConstants).Copy Worksheets("Destination").Range("missing_qbc")
End Sub
我的源数据 Z4:Z20000
具有返回值(文本/数字/分数等)或空白"的公式.我希望副本忽略空格,但复制其他任何返回的值
My source data Z4:Z20000
has formulas that returns a value (texts/numbers/fraction etc) or blank "". I want the copy to ignore the blanks, but copy any other value returned
由于源范围内的公式,上面使用 SpecialCells(xlCellTypeConstants)
的VBA代码无法正常工作.
The VBA code above using SpecialCells(xlCellTypeConstants)
doesn't work because of the formula in the source range.
我的问题:有没有一种简单的方法可以使用 range.specialcells
将我的数据从工作表复制到另一个表,请记住源单元格包含公式,并且该公式可能会产生空字符串单元格,将需要跳过
My question: Is there a straightforward way I can use range.specialcells
to copy my data from a worksheet to another bearing in mind that source cells contain formulas and the formulas may produce empty string cells which will need to be skipped
推荐答案
我能想到的最简单的方法是在复制所有内容后删除空格:
The easiest way I can think of is to remove the blanks after copying all:
Set rngFrom = [Source!Z4:Z2000]
Set rngTo = [Destination!missing_qbc].Resize(rngFrom.Rows.Count, 1)
rngTo.Value = rngFrom.Value
rngTo.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
更复杂的方法是使用数组公式,但不需要VBA.
The more complicated way is with array formula, but doesn't need VBA.
这篇关于Excel中的SpecialCells返回公式的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!