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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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