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!
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,070
Messages
5,599,607
Members
414,323
Latest member
Sacalumbo

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