在下面的代码中,我希望看到sum公式,这样我就可以看到哪些单元格正在相加,但代码只是反射结果而不是公式[like this" =SUM(B2:F2)].希望你能理解我的问题并在这方面提供帮助。
Sub Macro6()
Dim UserResponse As Range
Dim Result As Range
Set Result = Application.InputBox("Select cell where you want result", Default:=Selection.Address, Type:=8)
Set UserResponse = Application.InputBox("select a range with the mouse", Default:=Selection.Address, Type:=8)
Result.Value = Application.WorksheetFunction.Sum(UserResponse)
End Sub发布于 2019-09-08 12:46:59
我可能会因为这个答案而被否决,但这是值得的!
MsgBox "=SUM(" & Replace(UserResponse.Address, Chr(36), vbNullString) & ")"
发布于 2019-09-08 16:43:44
尝试下面的代码。这应该行得通。
Sub Macro6()
Dim UserResponse As Range
Dim Result As Range
Set Result = Application.InputBox("Select cell where you want result", Default:=Selection.Address, Type:=8)
Set UserResponse = Application.InputBox("select a range with the mouse", Default:=Selection.Address, Type:=8)
Result.Formula = "=SUM(" & UserResponse.Address & ")"
End Sub或者在最后一行中,您可以使用"=SUM(" & UserResponse.Address (False, False) & ")",这样公式就不会被绝对引用。
https://stackoverflow.com/questions/57837938
复制相似问题