Changing Value To Negative Value
Changing Value To Negative Value
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Changing Value To Negative Value

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    26
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Hi,

    I would really appreciate some help with this. I have a combo box with 2 columns , Column A is the Bound Column with 3 selections 9010, 9020, 9030. Next to the Combobox is Textbox1 where a total is to be entered.If 9010 or 9020 is selected the total is a positive total but when 9030 is selected it should be a negative total. Is there any code that would place a minus sign infront of the total if 9030 is selected?

    I have been trying to find help on this but I cannot find anything. Any help would be appreciated.

    Mareene

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Mareene

    Try this code:


    Code:
    Private Sub ComboBox1_Change()
    Dim iNum As Integer
    
    If ComboBox1.ListIndex > -1 Then
     iNum = Combobobox1
      If iNum = 9030 Then
         textbox1 = iNum * -1
      Else
         textbox1 = iNum
      End If
    End If
    
    End Sub

  3. #3
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    I created a UserForm with 2 controls, one Combobox (ComboBox1) and one Textbox (TextBox1), then, used the following code, which worked ok.

    Code:
    Private Sub ComboBox1_Change()
    If Len(TextBox1) > 0 Then
        Select Case ComboBox1.ListIndex
        Case 0, 1
            If InStr(TextBox1, "-") > 0 Then TextBox1 = Application.Substitute(TextBox1, "-", "")
        Case 2
            If InStr(TextBox1, "-") = 0 Then TextBox1 = "-" & TextBox1
        End Select
    End If
    End Sub
    
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If Len(TextBox1) > 0 Then
        Select Case ComboBox1.ListIndex
        Case 0, 1
            If InStr(TextBox1, "-") > 0 Then TextBox1 = Application.Substitute(TextBox1, "-", "")
        Case 2
            If InStr(TextBox1, "-") = 0 Then TextBox1 = "-" & TextBox1
        End Select
    End If
    End Sub
    
    Private Sub UserForm_Initialize()
    ComboBox1.AddItem "9010"
    ComboBox1.AddItem "9020"
    ComboBox1.AddItem "9030"
    End Sub
    Regards,

    Juan Pablo González
    http://www.juanpg.com

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com