How convert minus value to positive after show in label on userform

Alaa mg

Active Member
Joined
May 29, 2021
Messages
378
Office Version
  1. 2019
Hi again,
I try to change minus value to positive and positive to minus , but the problem minus value doesn't change to positive value in Label4 on userform as bold in line, how I fix that,please?
Rich (BB code):
Private Sub ComboBox1_Change()
I
If ComboBox1.ListIndex = -1 Then Exit Sub
If ComboBox1.Value <> "" Then
Dim lRow As Integer
lRow = Application.Match(ComboBox1.Value, Sheets("CUSS").Range("B:B"), 0)
Label4.Caption = Format(Cells(lRow, 5).Value, "#,##0.00#")
End If
If Label4.Caption < 0 Then Label4.Caption = Label4.Caption * -1
If Label4.Caption > 0 Then Label4.Caption = Label4.Caption * -1
Label4.Caption = Format(Label4.Caption, "#,##0.00")
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You do not need all the IF checks. Simply use the Abs (absolute value) function on the value, i.e.
Rich (BB code):
Label4.Caption = Format(Abs(Cells(lRow, 5).Value), "#,##0.00#")
 
Upvote 0
I'm not sure what You mean ?!
do you mean I don't need these?
Rich (BB code):
If Label4.Caption < 0 Then Label4.Caption = Label4.Caption * -1
If Label4.Caption > 0 Then Label4.Caption = Label4.Caption * -1
Label4.Caption = Format(Label4.Caption, "#,##0.00")
 
Upvote 0
Correct.
And replace this line you currently have:
VBA Code:
Label4.Caption = Format(Cells(lRow, 5).Value, "#,##0.00#")
with this:
VBA Code:
Label4.Caption = Format(Abs(Cells(lRow, 5).Value), "#,##0.00#")
 
Upvote 0
OK but will not change positive to minus !
Whoops! I misread that. I thought you wanted to simply make them all positive.
But if you want to flip them (make positive into a negative, and a negative into a positive), simply multiply the value portion by -1, i.e.
VBA Code:
Label4.Caption = Format(Cells(lRow, 5)*-1, "#,##0.00#")
 
Upvote 0
so should be this ,just I would make sure there is no error.
VBA Code:
Label4.Caption = Format(Abs(Cells(lRow, 5) * -1), "#,##0.00#")
Label4.Caption = Format(Cells(lRow, 5) * -1, "#,##0.00#")
right?
 
Upvote 0
No, you only need the bottom one. That replaces the top one with the ABS.
This should be all you need:
VBA Code:
Label4.Caption = Format(Cells(lRow, 5) * -1, "#,##0.00#")
 
Upvote 0
Solution
No, you only need the bottom one. That replaces the top one with the ABS.
misunderstood , sorry!🙏🙏
now it works greatly .(y)
thank you so much for help me again.:)
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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