• textbox as value, not text (2002)

    Author
    Topic
    #393982

    I have a worksheet with several textboxes I inserted from the Control Toolboox. I linked the textboxes to cells in my spreadsheet.

    When I input the numbers in the textboxes, number as text are entered in the linked cells. I have several formulas that use the linked cells numbers, so I need numbers, not text in my linked cells.

    How do I solve this?

    Thank you

    Viewing 3 reply threads
    Author
    Replies
    • #718508

      You can use the VALUE function to convert the text to values. If your Textbox returns contents to A1, =VALUE(A1) will return a numeric value, provided of course that the contents can be evaluated a numeric value.

      Andrew C

    • #718509

      You can use the VALUE function to convert the text to values. If your Textbox returns contents to A1, =VALUE(A1) will return a numeric value, provided of course that the contents can be evaluated a numeric value.

      Andrew C

    • #718699

      That would work.

      But,,,, problem: I have several formulas that refer to A1. And replacing A1 in the formulas , for Value(A1), would add a lot of text in my formulas and make syntax difficult to understand. (I have several cells that are linked to several textboxes. These cells provide numeric data to the formulas)

      Is there a way I can format the text box so the cell receives the numbers that the user is typing , already as numeric data, so I dont have to edit the formulas?

      Thank you

      • #718707

        Put the cellLink in another cell (eg A2), then put in A1 =value(A2)

        Now all your fomulas will work without changing since A1 has a value.
        Steve

        • #718713

          User input in a textbox (inserted from the Control Toolbox and linked a spreadsheet cell) always defaults to text?

          There is no way to overide that? Not even with code?

          • #718741

            You could get the results of the textbox in a string variable
            Add to a single, double, long, or integer variable the results using Value (or other function) then place the results of the VALUE variable in the cell of interest. You would NOT be using the LinkedCell property at all in this case.

            Steve

            • #718764

              it seems that this does this does the trick:

              Private Sub x_spacing_Change() ‘ x_spacing is the textbox
              Dim userinput As Integer
              userinput = x_spacing.Value
              Sheets(“hidden_data”).Range(“xspace”).Value = userinput
              End Sub

              But I am surprised that although having and advanced user interface like the properties window for the textbox, that it slipped from the developers, that textbox user input could be formatted there as an option! Recognizing user input as text , numbers, etc and sending with that format to the linked cell should be straight forward and automatic.

              Thank you

            • #718793

              You might want to add error checking. If the TEXT they entered can not be interpreted as an integer, you will get a runtime error

              Steve

            • #718799

              how would I do that?

            • #718865

              Here is some simple code. It checks to see if the “string” is a number and if it is, enter it as an integer, if not it beeps and gets rid of the last item entered.

              Steve

              Option Explicit
              Private Sub x_spacing_Change() ' x_spacing is the textbox
                  Dim sUserInput As String
                     
                  sUserInput = x_spacing.Value
                  If IsNumeric(sUserInput) Then
                      Sheets("hidden_data").Range("xspace").Value = _
                          Int(sUserInput)
                  Else
                      Beep
                      If sUserInput  "" Then _
                          x_spacing.Value = _
                              Left(sUserInput, Len(sUserInput) - 1)
                  End If
              End Sub
            • #718866

              Here is some simple code. It checks to see if the “string” is a number and if it is, enter it as an integer, if not it beeps and gets rid of the last item entered.

              Steve

              Option Explicit
              Private Sub x_spacing_Change() ' x_spacing is the textbox
                  Dim sUserInput As String
                     
                  sUserInput = x_spacing.Value
                  If IsNumeric(sUserInput) Then
                      Sheets("hidden_data").Range("xspace").Value = _
                          Int(sUserInput)
                  Else
                      Beep
                      If sUserInput  "" Then _
                          x_spacing.Value = _
                              Left(sUserInput, Len(sUserInput) - 1)
                  End If
              End Sub
            • #718800

              how would I do that?

            • #718794

              You might want to add error checking. If the TEXT they entered can not be interpreted as an integer, you will get a runtime error

              Steve

            • #718765

              it seems that this does this does the trick:

              Private Sub x_spacing_Change() ‘ x_spacing is the textbox
              Dim userinput As Integer
              userinput = x_spacing.Value
              Sheets(“hidden_data”).Range(“xspace”).Value = userinput
              End Sub

              But I am surprised that although having and advanced user interface like the properties window for the textbox, that it slipped from the developers, that textbox user input could be formatted there as an option! Recognizing user input as text , numbers, etc and sending with that format to the linked cell should be straight forward and automatic.

              Thank you

          • #718742

            You could get the results of the textbox in a string variable
            Add to a single, double, long, or integer variable the results using Value (or other function) then place the results of the VALUE variable in the cell of interest. You would NOT be using the LinkedCell property at all in this case.

            Steve

          • #718762

            That’s what it is called a TEXTbox. yep

            If you don’t link the textbox to the cell, then you could use the textbox change event routine VBA code to take the text from the textbox, convert it to a number, and store the number into the cell.

          • #718763

            That’s what it is called a TEXTbox. yep

            If you don’t link the textbox to the cell, then you could use the textbox change event routine VBA code to take the text from the textbox, convert it to a number, and store the number into the cell.

        • #718714

          User input in a textbox (inserted from the Control Toolbox and linked a spreadsheet cell) always defaults to text?

          There is no way to overide that? Not even with code?

      • #718708

        Put the cellLink in another cell (eg A2), then put in A1 =value(A2)

        Now all your fomulas will work without changing since A1 has a value.
        Steve

    • #718700

      That would work.

      But,,,, problem: I have several formulas that refer to A1. And replacing A1 in the formulas , for Value(A1), would add a lot of text in my formulas and make syntax difficult to understand. (I have several cells that are linked to several textboxes. These cells provide numeric data to the formulas)

      Is there a way I can format the text box so the cell receives the numbers that the user is typing , already as numeric data, so I dont have to edit the formulas?

      Thank you

    Viewing 3 reply threads
    Reply To: textbox as value, not text (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: