Help/Advice on VBA Input Box Code

lewis94

New Member
Joined
Nov 2, 2008
Messages
14
Hi All,

I wonder if anyone could help me tidy up the code below for an Input box and then the output from this

The code is shown below for an input project name.

Inputt = InputBox("Please enter a Main Project Title." & vbNewLine & vbNewLine & vbNewLine & "Example: Sample_Project_1" & vbNewLine & vbNewLine & vbNewLine & "Please note the use of underscore for project names" & vbNewLine & vbNewLine & "Thankyou", "Add New Project")
', "Enter Scheme Titles"
arr = Split(Inputt, ",")
If Inputt = " " Then

Exit Sub

1669104697786.png


What I want to do is use a similar Input box but be able to input text/project names without the underscore

Also how could I then output this to a line on a sheet, say cell Z7
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,

If you want a choice between project name styles then I suggest make a function of the code & pass an argument to it to determine which style to use

Place following in a STANDARD module

VBA Code:
Function GetInput(Optional ByVal WhichStyle As Long = 1) As String
    Dim strPrompt(1 To 2) As String
    Dim Entry             As Variant
   
    Const NewLine   As Variant = vbNewLine & vbNewLine & vbNewLine
   
    strPrompt(1) = "Please enter a Main Project Title."
    strPrompt(2) = strPrompt(1) & NewLine & "Example: Sample_Project_1" & NewLine & _
                   "Please note the use of underscore For project names" & NewLine & "Thankyou"
   
    Do
        Entry = InputBox(strPrompt(WhichStyle), "Add New Project")
        'cancel pressed
        If StrPtr(Entry) = 0 Then Exit Function
    Loop Until WhichStyle = 1 And Len(Entry) > 0 Or WhichStyle = 2 And InStr(1, Entry, "_") > 0
   
    GetInput = Entry
   
End Function

And then to call it from your code

VBA Code:
Sub Mytest()
    Dim myproject As String

    myproject = GetInput(WhichStyle:=1)

    Worksheets("Sheet1").Range("Z7").Value = myproject
End Sub


Which style is displayed by entering

1 (default) for basic project name

2 for project name with underscore

Dave
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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