简体   繁体   中英

VBA using .Formula in Excel returns 0 when the Range.Value is Empty

if the result of the .Formula = "='C:\\data\\[adxl364.xls]ADXL364_QC'!A1" is empty, it returns a value of 0 in my Worksheet .

what should I add to the code for it not to return a value of 0 when the Cell is empty?

Sub GetRange()
    With Range("A:Z")
        .Formula = "='C:\data\[adxl364.xls]ADXL364_QC'!A1"
        .Formula = .Value
    End With
End Sub

You need to modify your formula to return an empty string when "..!A1" does not = 0.

Sub GetRange()
    With Range("A:Z")
        .Formula = "=If('C:\data\[adxl364.xls]ADXL364_QC'!A1 > 0,'C:\data\[adxl364.xls]ADXL364_QC'!A1,Text(,))"
        .Formula = .Value
    End With
End Sub

I use Text(,) to return an empty string instead of doubling up the double quotation marks (eg """"):

"=If('C:\data\[adxl364.xls]ADXL364_QC'!A1 > 0,'C:\data\[adxl364.xls]ADXL364_QC'!A1,"""")"

您可以使用以下函数: =IF(ISBLANK('C:\\data\\[adxl364.xls]ADXL364_QC'!A1);"";'C:\\data\\[adxl364.xls]ADXL364_QC'!A1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM