excel 不一致时出现“Copy Formula From Above”(从上面复制公式)

x33g5p2x  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(114)

我希望Excel在发现不一致的单元格时自动复制

Sub IGNOREINCONSISTENT()
Dim r As Range: Set r = Range("Your Range")
Dim cel As Range

For Each cel In r
    cel.Errors(xlInconsistentFormula).ignore = True
Next cel
End Sub

这是我在论坛中找到的代码,但忽略不

有什么解决办法吗?

b5lpy0ml

b5lpy0ml1#

这就是你想要的吗?

代码

Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim rng As Range
    Dim FRange As Range
    Dim aCell As Range
    
    '~~> Change this to the relevant worksheet
    Set ws = Sheet1
    
    '~~> Change this to the relevant range
    Set rng = ws.Range("A1:A10")
    
    '~~> Work with only those cells which have formula
    On Error Resume Next
    Set FRange = rng.SpecialCells(xlCellTypeFormulas)
    On Error GoTo 0
    
    '~~> Check if there are cells which have formula
    If FRange Is Nothing Then
        MsgBox "No cells with formula found"
        Exit Sub
    End If
    
    '~~> Filldown on cells which have Inconsistent Formula
    For Each aCell In FRange
        '~~> .FillDown in a single cell will pull the formula down.
        '~~> Just like when you press Ctrl + D
        If aCell.Errors.Item(xlInconsistentFormula).Value = True _
        Then aCell.FillDown
    Next aCell
End Sub

行动中

相关问题