Input Box

ronicaroman

New Member
Joined
Dec 2, 2011
Messages
25
I'd like to add an Input Box which will create a header cosisting of three lines of text. The three prompts for the user should be:

1. Please enter account name.
2. Please enter account number/company code.
3. Please enter time frame.

Does anyone know the VBA code for this? And how can I add the user's response to the header of the spreadsheet?
 
Here's a simple approach...

Code:
Sub getinfo()
    Dim sIn As String
    Do While sIn = ""
        sIn = InputBox("Please enter account name.")
    Loop
    Range("A1") = sIn
    sIn = ""
      Do While sIn = ""
        sIn = InputBox("Please enter account number/company code.")
    Loop
    Range("B1") = sIn
    sIn = ""
    Do While sIn = ""
        sIn = InputBox("Please enter time frame.")
    Loop
    Range("C1") = sIn
End Sub
 
Upvote 0
Thanks for your input, but that adds the answers to A1, A2, and A3 but not into the header of the document. Is there any way to add the three lines into the actual header?
 
Upvote 0
sorry I missed that. How is this?

Code:
Sub getinfo()
    Dim sIn As String
    Do While sIn = ""
        sIn = InputBox("Please enter account name.")
    Loop
    ActiveSheet.PageSetup.LeftHeader = sIn
    sIn = ""
    Do While sIn = ""
        sIn = InputBox("Please enter account number/company code.")
    Loop
    ActiveSheet.PageSetup.CenterHeader = sIn
    sIn = ""
    Do While sIn = ""
        sIn = InputBox("Please enter time frame.")
    Loop
    ActiveSheet.PageSetup.RightHeader = sIn
End Sub
 
Upvote 0
That should work, but is there any way for all three lines to appear in the center header one under the other?
 
Upvote 0
Code:
Sub getinfoA()
    Dim sIn As String
    Do While sIn = ""
        sIn = InputBox("Please enter account name.")
    Loop
    a = sIn
    sIn = ""
    Do While sIn = ""
        sIn = InputBox("Please enter account number/company code.")
    Loop
    b = sIn
    sIn = ""
    Do While sIn = ""
        sIn = InputBox("Please enter time frame.")
    Loop
    c = sIn
    ActiveSheet.PageSetup.CenterHeader = a & vbLf & b & vbLf & c
End Sub

@tlowry
Handy code for me. Thanks
John
 
Upvote 0

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