![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
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
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|