From Cell to InputBox

  • Thread starter Thread starter Robin Clay
  • Start date Start date
R

Robin Clay

Greetings !

My code, after a "button" is pressed, throws an InputBox
onto the screen.

I want in reply to insert a value already displayed in a
Cell.

This I can do by selecting the cell before hand, pressing
F9 and then Ctrl C followed by Esc. Then I click on
the "button", and press Ctrl V at the InputBox.

That's fine for one value, but the InputBox is followed by
another, into which I want to paste the value from another
cell.

Yes, I COULD type it in - but that's not a satisfactory
solution !

I guess one way would be to type in the Cell Reference -
but is there a way that I could click on the required
Cell ?

There are ocasions when (say) "G72" would be a valid
answer, when I actually want the VALUE in that Cell (which
might be "J136", say)


RClay AT haswell DOT com
 
Try the following macro:

Sub SetValueInputBox()
ActValue = ActiveCell.Value
' or
' ActValue=cells(5,3).value
Answer = InputBox("Input Value", "Input", ActValue)
End Sub

If you use "ActValue = ActiveCell.Value" the default value
in the InputBox is the value of the actually selected cell.
If you use "ActValue = cells(5,3).Value" the default value
in the InputBox is the value of the actually selected cell.

Regards
Klaus
 
Dim rng as Range
On Error Resume Next
set rng = Application.InputBox("Select cell with mouse", Type:=8)
On Error goto 0
if not rng is nothing then
vVal = rng(1).value
else
msgbox "you hit cancel"
End if

This will get a reference to the selected cell or you can type in an
address. You can't type in the value, however.

Once you have the cell reference, your code can use the value of that cell.
 
Back
Top