Auto-populate input box with array value

jgscanlon

New Member
Joined
Jan 8, 2014
Messages
46
Good morning!

Using VBA I am creating a dynamic array using the values present in a text file. Users are then prompted to type in a value via an input box; if the value entered in the input box is not in the array, an error message appears, prompting them to cancel or retry their entry.

In some instances, there is only one value in the array; in those cases, I'd like to auto-populate the input box entry. How can I accomplish this?

Thank you!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

jgscanlon

New Member
Joined
Jan 8, 2014
Messages
46
Solved it! If the number of values in my array is equal to 1, then I set the value of my input box equal to Array(1), otherwise I require an input.

Section of code: GroupCode is my Dynamic Array, defined in another section of code.

Code:
    NumberOfGroups = UBound(GroupCode) - LBound(GroupCode) + 1
    If NumberOfGroups = 1 Then RunGroup = GroupCode(1): GoTo Begin Else
        RunGroup = Application.InputBox(prompt:="Enter the group code for this 3D run.", Type:=2)
        If IsInArray(RunGroup, GroupCode) = False Then
            If MsgBox(RunGroup & " is not a valid entry. Try again?", vbRetryCancel) = vbRetry Then GoTo DefineGroup
            GoTo Cancel
        Else
            GoTo Begin
    End If
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,550
Messages
5,832,418
Members
430,132
Latest member
Bdesai

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
Top