• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code for If with multiple conditions

mery

New Member
Hello Everyone.
I am working on one project and, among other things, I need certain results for further work. These results that I will use later are from columns (F, G and H). To get the data that I could process later, I used columns J and K to extract a number from columns D and E (using the function), then I used that number later under certain conditions.

The results I need to get are:
To get the results in column F (status 1) if the following condition is met:
- That the cells in column B contain the string "Weekly" and that the date from the cells in column C is less or equal than to the date in cell L2 (result "Yes")
- All other conditions (result "No")

To get the results in column G (status 2) if the following conditions are met:
- That the cells in column B contain the string "Daily", that the date from the cells in column C is greater or equal than to the date in cell L2 and that the number from the cells in column K is greater than the cells in column J (result "Yes")
- All other conditions (result "No")

To get the results in column H (status 3) if the following conditions are met:
- That the cells in column B contain the string "Weekly", that the date from the cells in column C is greater or equal than to the date in cell L2 and that the number from the cells in column K is greater than the cells in column J (result "Yes")
- All other conditions (result "No")

The code I made gives the necessary results, but somehow it seems to me that the code is too complicated (by my opinion). Is this the right way or maybe you have some other suggestion?
 

Attachments

  • sample.xlsm
    121.6 KB · Views: 16
Hi,​
no need a code just using Excel basics : beginner level formulas.​
If really really really a code is necessary as the same formulas can be used within …​
 
mery
I would do this way...
Press Cell M1 --- [ Do It ] -button -- 'my way'
Press Cell N1 --- [ Do It ] -button -- 'other way'

... yes Marc L ... with Excel Basics ;)
 

Attachments

  • sample (1).xlsb
    66.5 KB · Views: 9
… including columns J & K as an user defined function is useless, again just with formulas.​
So all can be done without any code just with easy formulas and, if really a VBA procedure is necessary,​
the right & easy way is to not use any loop but the same formulas, needing 5 codelines,​
even if only results are wanted without any formula in cells (so with just 2 additional codelines).​
 
That's what I was looking for.
Thanks a lot for the help. It is much faster and easier on this way.
 
If a VBA procedure is necessary, try first formulas manually in cell J2 & K2, once well working even when copied down,​
operate formulas in cells F2, G2, H2 and once well working even when copied down,​
post them here (only J2 & K2 and F2, G2 & H2) so then I will show you how to use them in a VBA procedure​
as that's fastest & easiest than using a loop, just with around 10 codelines maximum !​
Tell also if you want the formulas staying in cells or just the results without any formula remaining …​
 
Back
Top