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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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
Noted, will do rounding first next time if i do equality, thanks a lot :)
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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