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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,467
Members
452,516
Latest member
archcalx

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