View Single Post
  #19   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Getting input within macro without the input box

You can test this code example as a macro
Change this line

Set myRange = Range("a1,b3,d7")

Sub With_InputBox()
Dim myRange As Range
Dim myCell As Range
Dim myAns As Variant
Set myRange = Range("a1,b3,d7")
For Each myCell In myRange.Cells
myAns = InputBox _
(prompt:="Please enter something for cell: " _
& myCell.Address, Title:="Get Data")
If myAns < "" Then
myCell.Value = myAns
End If
Next myCell
End Sub


You can run the macro when you activate the worksheet
See
http://www.cpearson.com/excel/vbe.htm




--
Regards Ron de Bruin
http://www.rondebruin.nl



"JR Hester" wrote in message ...
I can't take credit for the code referenced in the oroginal post. It was
imported from response to an earlier thread, and unfortunately I can't recall
the resxponder who offered this solution.
I believe this was copied into a worksheet change event, but can't recall
the method of accessing that particular macro code. There are no "variables"
other than the "InputData" declared in the first line. It was setup to
automatically ec\xecute as soon as the spreadshett was opened.

This was functioning, and I eventually duplicated this sequence through
about 64 iterations totaling some 192 lines of code. This process worked,
however it was confusing my users as the dialog box ususally hid the actual
cell the data was being stored to.

I reposted this thread t\looking for a more simple and direct way to simply
move teh active cell from one specific location to another upon pressing teh
ENTER key. PAUL SIMON offered the most efficient solution with a series of
defined ranges. If you simply need to move from one non-contigous cell to
another, I suggest you look through the Paul Simon postings above! A very
simple and functional solution.

Hope thsi helps

"lschuh" wrote:

I am trying to use the code you put in this post but I don't know where in
the vba it goes. Should it go in a sub from within the worksheet? Where are
the variables declared? Also I can't get most of the code to work. Should
it be all in one place? I want to open the spreadsheet on the first line
that the user will be putting his data into. I then want to go from the next
user cell and so on until the end of the form. How would I go about using
your code and where?

"JR Hester" wrote:

Thanks to all the posters and responders, whose Q&A I've read to get me this
far.

I am looking for a simple way to direct users through a spreadsheet and
accept data entry in specific locations. I have the following code that is
functional, but I wonder if thre might not be a more efficient way of
accomplishing this task. I would prefer to simply move to a cell, and accept
data entry directly into the cell, then advance to the next assigned location
when the ENTER key finalizes the cell input.
With 64 non-contiguous cells requiring data entry, you amy see why I am
looking for a shorter solution. Plus my users are used to teh look and feel
of the spreadsheet cells, and the dialog boxes confuse them.

Here is currently functional macro, for first three cells only

Dim InputData As String
Application.Goto reference:=Range("B1") ' go to B2 on open sheet
InputData = InputBox("Promt to input", "Please input your data", "")
Range("B1").Value = InputData 'Retrieve InputData value to range B1
Application.Goto reference:=Range("G1")
InputData = InputBox("Promt to input", "Please input your data", "")
Range("G1").Value = InputData 'place data into cell G1
Application.Goto reference:=Range("C4") 'Go to C4, accept data
InputData = InputBox("Promt to input", "Please input your data", "")
Range("C4").Value = InputData 'Retrieve InputData value to range C4
'
Thanks for any suggestion, pointers etc.