Reputation: 327
I'm trying to develop a MsgBox
which displays a question in the MsgBox
fed from a cell reference.
So in the example below the Msg "Please Enter The Number Of Hectares", I want to be picked up from say Worksheet1 cell A1
.
Sub ComplainceQuestion()
On Error Resume Next
Dim num As Double
Dim Save
num = Application.InputBox(prompt:="Please Enter The Number Of Hectares", Type:=1)
MsgBox Format(num * 2.47105, "#,##0.00") & " Is the Number Of Acre's."
Save = MsgBox("Do you want to paste the result in a cell?", vbYesNo)
If Save = vbYes Then
Cell = Application.InputBox("Type In The Cell Reference, for example 'G64'")
Range(Cell).Value = num * 2.471054
End If
End Sub
Upvotes: 0
Views: 1409
Reputation: 519
In your original code num is assigned the value of the user's input. To assign it the value of a cell, such as A1, just change the line num = Application.Inputbox... to num = Range("A1").value. Modified code:
Sub ComplainceQuestion()
On Error Resume Next
Dim num As Double
Dim Save
num = Range("A1").Value
MsgBox Format(num * 2.47105, "#,##0.00") & " Is the Number Of Acre's."
Save = MsgBox("Do you want to paste the result in a cell?", vbYesNo)
If Save = vbYes Then
Cell = Application.InputBox("Type In The Cell Reference, for example 'G64'")
Range(Cell).Value = num * 2.471054
End If
End Sub
Edit: change that before mentioned line to num = Application.InputBox(prompt:=Range("A1").Value, Type:=1)
Upvotes: 3