我的目标是能够因缺乏更好的术语而“翻译”;工作表范围内的每个单元格都进入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)我不知道该怎么写
答案 0 :(得分:0)
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