Add Second Input Box

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi,

Can someone help me with this please? Originally I was having trouble with entering a date in the input box, but that now works really well.
Now I want to add another input box which asks for the user name (see last 2x lines of code below. This part isn't working or looking right. I wouldn't mind if both input boxes came up at the same time, if possible/easy enough to do..

VBA Code:
Private Sub Post_Journal()
 Dim StartDate As Date
 Dim MsgDate As String
 Dim TitleDate As String
 Dim response As String
 
 MsgDate = "Enter date journal posted (d/mm/yy)"
    TitleMsg = "Journal Post Date"
 
curdate = Date

StartDate = Application.InputBox(MsgDate, TitleMsg, FormatDateTime(curdate, vbShortDate), Type:=1)

Range("Z2").Value = StartDate

reponse = InputBox("Enter User Name")
Range("Z1").Value = response

End Sub

Thank you!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
To solve your one problem you have
reponse
and
response

These are not the same. Look closely at the spelling
 
Upvote 0
Would you like to see my script?
If so here it is but maybe you like yours best.

In this script in the Inputbox enter:
Date then a comma then the Name
I have this defaulting to Todays Date and the User Name using this app.
Modify to your specific needs.
Does not require two Inputboxes
VBA Code:
Sub My_Input()
'Modified 3/20/2020 4:26:41 AM EST
On Error GoTo M
Dim StartDate As String
Dim LString As String
Dim LArray() As String
LArray = Split(LString, ",")
Dim UserName As String
UserName = Application.UserName

StartDate = Application.InputBox("Enter Date then a comma and name", "Like This: " & Date & "," & UserName, Date & "," & UserName)
LString = StartDate
LArray = Split(LString, ",")
Range("Z2").Value = Format(LArray(0), "d/mm/yy")
Range("Z1").Value = LArray(1)
Exit Sub
M:
MsgBox "Something went wrong" & vbNewLine & "Maybe you did not enter a comma"
End Sub
 
Upvote 0
Another suggestion, however, this still relies on 2 input boxes, than a single input box:
VBA Code:
Sub something()
    With Application
        Cells(1, 26).Resize(2).Value = .Transpose(Array(InputBox("Enter name: ", "Enter name", .UserName), InputBox("Enter date: ", "EnterDate", Date)))
    End With
End Sub
If you must have separate input fields for a User to enter data in a single "input", then User Forms will be better suited for this. You can find examples of User Forms online.
 
Upvote 0
To solve your one problem you have
reponse
and
response

These are not the same. Look closely at the spelling

Thank you for pointing this out (and for your other suggested post).
I have decided to go with the following, which looks and works fine (I'll keep the 2x input boxes).
I was wondering, with the default user entry, is it possible to refer to a cell or a named range? In the below, I'm trying to get it to return the value of A1 as the default entry. Thank you!

VBA Code:
Private Sub Post_Journal()
 Dim StartDate As Date
 Dim MsgDate As String
 Dim TitleDate As String
 Dim response As Variant

 
 MsgDate = "Enter date journal posted (d/mm/yy)"
    TitleMsg = "Journal Post Date"
 
curdate = Date

StartDate = Application.InputBox(MsgDate, TitleMsg, FormatDateTime(curdate, vbShortDate), Type:=1)

Range("Z2").Value = StartDate

response = Application.InputBox("Please enter user name", "User Name", "A1")
Range("Z1").Value = response


End Sub
 
Upvote 0
So if I understand you showed me your original script. And said you wanted it modified so you would not need 2 Inputboxes. So I provided a script that would not require 2 input boxes. But now you say you want to go back to doing things like before but only want some additional changes made is that correct?
 
Upvote 0
Try this:
VBA Code:
Sub Post_Journal()
'Modified 3/22/2020 8:08:05 PM EST
Dim StartDate As Date
Dim MsgDate As String
Dim TitleDate As String
 Dim response As Variant
 
MsgDate = "Enter date journal posted (d/mm/yy)"
TitleMsg = "Journal Post Date"

curdate = Date
StartDate = Application.InputBox(MsgDate, TitleMsg, FormatDateTime(curdate, vbShortDate), Type:=1)
Range("Z2").Value = StartDate
response = Application.InputBox("Please enter user name", "User Name", Range("A1").Value)
Range("Z1").Value = response

End Sub
 
Upvote 0
Solution
Just curious what did you not like about my solution other then default setting.
It did what you asked for correct?
 
Upvote 0
So if I understand you showed me your original script. And said you wanted it modified so you would not need 2 Inputboxes. So I provided a script that would not require 2 input boxes. But now you say you want to go back to doing things like before but only want some additional changes made is that correct?
When I was googling solutions, I found a neat illustration which showed two questions being asked in the one pop-up box. However, I now realise this was done by using a user form rather than input boxes.
If it was just me using the spreadsheet, I would have used your solution with separating by a comma but I feel that others may find it a bit complicated and so I decided to go back to the two separate boxes, which is clear cut - enter date - enter user name. I appreciate your time writing the code though! It did help me work out how to improve my existing code, so now both the pop-up boxes look the same, by putting in Application.InputBox.
 
Upvote 0
Ok.
But in your last post you said:
enter date - enter user name
But you asked for Date and Range(A1) value
So do you have what you want now

So if you always want user to enter Todays Date
Why need a Input Box Why not just have the script automatically enter Todays date.
And if always enter UserName why not have the script automatically do this with no need for any Input boxes.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top