简体   繁体   English

Excel VBA-用可变范围公式填充空的数据库单元格

[英]Excel VBA - Fill in empty database cells with variable range formula

I have a database containing "N/A" at different cells, caused by temporary system offline. 我有一个数据库,该数据库在不同的单元格中包含“ N / A”,这是由于暂时的系统离线导致的。 I used to fill these "N/A"'s using the formula shown with the image: 我曾经使用图像显示的公式来填充这些“ N / A”:

As you can see, the datum at columns A are cumulative, so are B and C. The "N/A"s are compensated by spreading the difference between the last reading before the first "N/A" and the first reading after the last "N/A" 如您所见,A列的基准是累积的,B和C也是累积的。“ N / A”通过散布第一个“ N / A”之前的最后一个读数与第一个“ N / A”之后的第一个读数之间的差来补偿。最后的“ N / A”

The "N/A"'s appear at different points and have varying lengths. “ N / A”出现在不同的点并具有不同的长度。

Is there maybe a vba code to help me do this in one click for the entire database? 也许有一个VBA代码可以帮助我一键完成整个数据库吗? Thank you sirs for your kind help. 谢谢您的帮助。

You could try running this VBA code to interpolate the N/A values based on numbers above and below: 您可以尝试运行此VBA代码以根据上下数字对N/A值进行插值:

Sub FillNA()

Dim rng As Range, col As Range, a As Range
Set rng = Cells.SpecialCells(xlCellTypeConstants, xlTextValues)

For Each col In ActiveSheet.UsedRange.Columns    
    If Not Intersect(rng, col) Is Nothing Then
        For Each a In Intersect(rng, col).Areas
            If a(1) = "N/A" Then
                a(0).Resize(a.Count + 2).DataSeries Trend:=True
            End If
        Next a    
    End If
Next col

End Sub

(If N/A appears at the beginning or end of the range you will need to decide how to handle this case and make appropriate adjustments) (如果N/A出现在范围的开始或结束时,你将需要决定如何处理这种情况,并作适当调整)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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