View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Can an input box do this

As with all programming, what code you use depends on how you want the
program to present itself to the user. The code for your request could be as
simple as this (where you would change the B1 cell reference to the address
of the cell you wanted to put the name in)...

Sub AddName()
Range("B1").Value = InputBox("Enter your name.")
End Sub

However, this will blank out B1 if the user hits enter without typing
anything or if he/she clicks the Cancel button. Perhaps this would be more
robust...

Sub AddName()
Dim EnteredName As String
EnteredName = InputBox("Enter your name.")
If Len(EnteredName) = 0 Then
MsgBox "You didn't enter anything!"
Else
Range("B1").Value = EnteredName
End If
End Sub

Of course, you can make your code even more intelligent than this.. again,
it all depends on how you want it to present itself.

--
Rick (MVP - Excel)


"Munchkin" wrote in message
...
Can a macro button activate a cell, then have an an input box pop up that
asks a user to enter their name, and upon doing so & clicking OK place the
name in the activaed cell?

I'm self taught at Visual Basics & can't figure how to do this. Am I
misunderstanding input boxes - or can an input box do this, and if so,
how?