vba question

Pinkyhello

New Member
Joined
May 6, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
Hello all,

i am trying to write a program where if the 3 cells in percentage adds up to 1 or 100 % then hightlight the 3 rows with %

i find that excel could read most of them except a particular combination


for below it's ok and can highlight rows in this order:
20%+10%+70%
70%+10%+20%
60%+10%+30%
30%+10%+60%
45%+45%+10%

but if the sequence change to, it cannot do the highlight and treat it as not =1
70%+20%+10%
20%+70%+10%
30%+60%+10%
60%+30%+10%

what could the problem be? i totally have no idea

 thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Just to illustrate:

Book1
ABC
170%20%10%
Sheet1


VBA Code:
Sub Test()

    Dim d As Double
    
    d = Range("A1").Value + Range("B1").Value + Range("C1").Value
    MsgBox d
    MsgBox d = 1
    MsgBox d - 1
    
End Sub
 
Upvote 0
Just to illustrate:

Book1
ABC
170%20%10%
Sheet1


VBA Code:
Sub Test()

    Dim d As Double
   
    d = Range("A1").Value + Range("B1").Value + Range("C1").Value
    MsgBox d
    MsgBox d = 1
    MsgBox d - 1
   
End Sub
ok i get it now, so maybe i will amend the formulas a bit, so it dont involve adding up percentages

thanks for the help! :)
 
Upvote 0
maybe i will amend the formulas a bit, so it dont involve adding up percentages
Just be aware that small rounding discrepancies can arise, not just with percentages.

So if you're testing for equality, you may need to round first.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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