VBA: Call Dynamic Messages for InputBox Function

zero269

Active Member
Joined
Jan 16, 2023
Messages
253
Office Version
  1. 365
Platform
  1. Windows
Hello,

Does anyone know if it's possible to use a dynamic message for an InputBox that is called on versus hard coded into the Procedure?

I understand how to customize an InputBox; one of my examples here:
VBA Code:
getNum = InputBox("Enter number of rows to insert", _
        "Insert Rows at end of Table", 1)

However, I'm wondering if it's possible to make that InputBox message dynamic based on another procedure.

For example:

I have a Function thanks to forum member Micron (here) that I'm using to prompt for a number of rows to insert into a Table (portion seen above).
I want to use the Function with another Procedure that enters a Due Date which enteres Today's date and then adds 21 days. I plan to create another one that prompts for the number of days to add. This is where the Dynamic Message comes into play.

In one scenario, the message is for the number of Table Rows to enter, while the 2nd one is asking for the number of Days to add.

Maybe something like:
VBA Code:
getNum = InputBox(DynamicPrompt, DynamicTitle, 1)

Instead of baking the custom Message into each Procedure, perhaps there's a way to create the various Messages and then Call on them within the given Procedure itself (for Days or Rows) to be passed to my getNum Function...?

Based on my various search results, I haven't come across anyone doing anything like this. However, I figured I would still raise the question here.

Thanks,
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Just add the dynamic message texts as parameters to the getNum function.

VBA Code:
Function getInput(ByVal Title As String, ByVal Prompt As String) As Variant
    getInput = InputBox(Prompt, Title, 1)
    If getInput = "" Then getInput = 0
End Function

Sub test()
    Dim Answer As Variant
    
    Answer = getInput("Enter number of rows to insert", "Insert Rows at end of Table")
    
    MsgBox "Number of rows entered : " & Answer
    
    Answer = getInput("Enter number of Days to add", "Add days")
    
    MsgBox "Number of days entered : " & Answer
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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