Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

excel vba how to shortcut criteria check with adding decimal as binary

good day,

I’ve made a program that has several prerequisites before proceeding and have written a scoring system to tally if all criteria are met without needing several if statements.

In addition i continue to write if statements if criteria are not met to alert the issue but this too is getting crazy with if a or b or c or d . . . statements is there a quicker mathematical way to summaries this? In some cases i have 6 or 7 prerequisites, isnt there a way i can count remainder or something of decimal to binary?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

here is a dummy example of what i mean

dim points as integer
points = 0

if len(range("A1") ) = 6 then points = points + 1             'example checks length
if Cdbl(range("B1") ) >= Cdbl(Date) then points = points + 2  'example checks if date is in future
if not isempty(range("C1")) then points = points + 4          'example checks field is not blank

if points = 7 then
    [do some code]
    msgbox "criteria met"

else

    ' this is what I want summarized with 1 nice mathematical equation

    if points = 1 or points = 3 or points = 5 or points = 7 then
        msgbox "problem is A1"
    end if

    if points = 2 or points = 3 or points = 6 or points = 7 then
        msgbox  "problem is B1"
    end if

    if points = 4 or points = 5 or points = 6 or points = 7 then
        msgbox "problem is C1"
    end if

end if

>Solution :

Yes. You to just need to use And. points And 1 will return 1 (which will be equivalent to true if used that way) if points is odd.

points And 6 will return 6 if the the number in binary ends in 110 or 111.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading