Creating an custom input box

K

Kain0o0

I was wondering if someone could help me here.
Im attempting to create an input box that will ask the user for a
number and in turn use this number to identify a sheet , then take
another input from the user and place it in a specific cell in the
sheet specified in the first step.

1.i will create an excel file with 31 sheets
2.when user runs file he will get a popup box asking for sheet wanted
3.the user will input a number between 1-31
4.a new box will open asking for data (lets assume a number)
5.Excel will place this value in Sheet(x) and a preassigned cell


Im very new to VBA so i apologise for the newbie post

any help on this owuld be appreciated. Thank you
 
J

Jason Morin

This should get you started. Press ALT+F11, double-click
on the ThisWorkbook module (if you don't see it, go to
View > Project Explorer), and paste in the code below.
Press ALT+Q and save the workbook. Close and re-open.

Option Explicit
Sub Workbook_Open()
Dim SheetNo As Long
Dim sPrompt1 As String
Dim sPrompt2 As String
Dim dValuetoCell As Double
Dim rTargetCell As Range

Set rTargetCell = Range("A1")
sPrompt1 = "Enter a number, 1-31:"
sPrompt2 = "Enter value to " & _
"insert into cell " & _
rTargetCell.Address(False, False) & ":"

SheetNo = Application. _
InputBox(prompt:=sPrompt1, Type:=1)

Worksheets(SheetNo).Select

dValuetoCell = Application. _
InputBox(prompt:=sPrompt2, Type:=1)

ActiveSheet.Cells(rTargetCell.Row, _
rTargetCell.Column).Value = dValuetoCell

End Sub

---
Not much error-checking. If the user types in "32" on the
first Inputbox, the code will error.

HTH
Jason
Atlanta, GA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top