PC Review


Reply
Thread Tools Rate Thread

Can an input box do this

 
 
Munchkin
Guest
Posts: n/a
 
      23rd May 2009
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?
 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      23rd May 2009
hi
vb101.
but which cell to activate?????
Sub addname()
Dim n As String
Range("B1").Activate
n = InputBox("what is your name?")
ActiveCell.Value = n
End Sub

regards
FSt1

"Munchkin" wrote:

> 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?

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd May 2009
You don't even need to activate the cell first. You can just plop the value
that the user typed right into the cell:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myStr As String

Set myCell = ActiveSheet.Range("C9")

myStr = InputBox(Prompt:="Please enter your name")

If Trim(myStr) = "" Then
Exit Sub 'user hit cancel
End If

myCell.Value = myStr

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros here:
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)


Munchkin wrote:
>
> 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?


--

Dave Peterson
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      23rd May 2009
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" <(E-Mail Removed)> wrote in message
news:FA477377-75BB-4D03-A2A8-(E-Mail Removed)...
> 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?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input mask date syntax-limit input to a number range =?Utf-8?B?QmlsbGlhbQ==?= Microsoft Access Database Table Design 2 18th Nov 2007 03:37 PM
How to change to default font from Asian input to Latin input? =?Utf-8?B?b3htb24=?= Microsoft Word Document Management 6 19th Apr 2006 12:50 AM
Make input selection access a table dependent upon another input =?Utf-8?B?ZGFiMTQ3Nw==?= Microsoft Access VBA Modules 4 4th Sep 2004 12:44 AM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Microsoft Excel Programming 4 8th Dec 2003 03:22 PM
Newbie Question: Limit Input Value baseon previouse input =?Utf-8?B?R3JlZW5Cb3k=?= Microsoft Access 5 8th Nov 2003 12:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:45 PM.