+ Reply to Thread
Results 1 to 6 of 6

Change entered number to negative

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2007
    Posts
    47

    Change entered number to negative

    Hello,

    I am using a User Form to enter data into a worksheet. I have radio buttons to select if the amount in a text box is either added or deducted. I would like to enter a plain number into the text box, and then when the data is put into the worksheet, it would automatically be positive or negative based on which radio button is checked.

    So if I enter that 250 units were deducted, it would show up on the worksheet as -250. If there were 250 units added, it would show up as 250.

    I can put a copy of the workbook on if anyone needs it.

    Thanks for any help.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Try something like:
    Private Sub CommandButton1_Click()
        Dim Tot As Long
        Tot = TextBox1.Value
        
        If OptionButton1 = True Then
        Range("A1") = Abs(Tot)
        ElseIf OptionButton2 = True Then
        Range("A1") = Abs(Tot) * -1
        End If
    End Sub

  3. #3
    Registered User
    Join Date
    03-01-2007
    Posts
    47
    Thanks for the help. Some simple math skills there would have helped me multiply by -1...

    Thanks again.

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Glad I could help.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You only need one Optionbutton really. If your Optionbutton1 controls negative amounts the something like this (change the code to write to your sheet).

    Private Sub CommandButton1_Click()
        If Me.OptionButton1 Then
            MsgBox Val(Me.TextBox1.Value) * -1
        Else: MsgBox Val(Me.TextBox1.Value)
        End If
    End Sub
    Note iy you declare Tot as long then you will not be able to use decimals.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    03-01-2007
    Posts
    47
    This is the code that I used. Pretty simple.

    If btnAdded.Value = True Then
        ActiveCell.Offset(0, 7).Value = txtAmount.Value
    ElseIf btnDeducted.Value = True Then
        ActiveCell.Offset(0, 7).Value = (txtAmount.Value * -1)
    End If
    thanks again for the help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1