Changing Value To Negative Value

camalita

New Member
Joined
Apr 8, 2002
Messages
26
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
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,268
Members
448,558
Latest member
aivin

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