0

I am a bit confused as to how to implement code for Text boxes. I am trying to set up a form which displays a text box, for which the user has the option to enter in the values (parameters) , which then are entered into another subprogram and runs that subprogram. For example, in the following code:

Option Explicit

Sub FillSampleTable()

'This will fill an x by y grid of numbers incrementing to use for testing purposes

Dim x As Double
Dim y As Double
Dim z As Double
Dim OffsetColumn As Integer
Dim offsetrows As Integer
Dim a As Long

Application.ScreenUpdating = False

a = 10
OffsetColumn = 1
offsetrows = 1
z = 0

For x = 1 To a

    For y = 1 To a

        z = z + 1
        Cells(x + offsetrows, y + OffsetColumn).Select
        Cells(x + offsetrows, y + OffsetColumn).Value = z

    Next y

Next x

Application.ScreenUpdating = True

End Sub

I would want to have a text box to prompt the user for the value of 'a', and once that value is loaded, then this subprogram is run. If no value is entered, then it would shoot an error msgbox and return to the entry screen. When I click the box I get:

 Private Sub GridSize_Change()
    'I renamed text box GridSize

    End Sub

but don't know what to do with this. MS Excel v 2016.

1 Answer 1

0

What you need is an inputbox.

You could do a simple :

a = InputBox("Enter number a")

Since you need a to be a positive integer, you should at least specify the datatype accepted by the inputbox to 1 (number). But you probably also need to make sure it is a positive integer.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you were right I accomplished this with an input box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.