【问题标题】:How to Apply Formula to every cell in range and print result for each cell in cell zz new line如何将公式应用于范围内的每个单元格并打印单元格 zz 新行中每个单元格的结果
【发布时间】:2019-05-22 11:28:44
【问题描述】:

我的目标是能够“翻译”没有更好的术语;将工作表范围内的每个单元格转换为 VBA。

这意味着我可以立即获取现有工作簿并生成 VBA 来重新创建它。

所以我把这个UDF放在一起。它显示了一个单元格,就像它出现在 VBA 中一样。 R1C1格式

Function showformula(rng As Range)
    If rng.HasArray = True Then
        showformula = "{" & rng.Formula & "}"
    Else
        showformula = "Sheets(""" & ActiveSheet.Name & """). Range(""" & rng.Address & """)" & ".FormulaR1C1 = " & """" & rng.FormulaR1C1 & """"
    End If
End Function

所以 1) 显示用于指定范围的用户选择框。然后单击继续,2) 上述 UDF 读取指定范围内的每个单元格,3) 在单元格 ZZ 中的新行上打印每个单元格的结果。

1 googlefu 很容易

但是 2) & 3) 我不知道该怎么写

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    https://www.reddit.com/r/excel/comments/brndla/how_to_apply_formula_to_every_cell_in_range_and/

    解决方案出现在这里

        Sub BuildList()
        Dim c As Range
        Dim rngInput As Range
        Dim rngOutput As Range
        Dim i As Long
    
        'Ask our user for stuff
        Set rngInput = Application.InputBox("What cells do you want to read?", "Input", , , , , , 8)
        Set rngOutput = Application.InputBox("Where do you want output to go?", "Output", , , , , , 8)
    
        Application.ScreenUpdating = False
    
        'Write the answers
        For Each c In rngInput.Cells
            rngOutput.Cells(1).Offset(i).Value = ShowFormula(c)
            i = i + 1
        Next c
        Application.ScreenUpdating = True
    End Sub
    
        Function ShowFormula(rng As Range)
            If rng.HasArray = True Then
                ShowFormula = "{" & rng.Formula & "}"
            Else
                ShowFormula = "Sheets(""" & ActiveSheet.Name & """). Range(""" & rng.Address & """)" & ".FormulaR1C1 = " & """" & rng.FormulaR1C1 & """"
            End If
        End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 2013-04-10
      • 2014-11-05
      相关资源
      最近更新 更多