Тёмный

Excel VBA IF THEN Statement (with ELSEIF & Looping in cells) 

Leila Gharani
Подписаться 2,6 млн
Просмотров 313 тыс.
50% 1

Join 400,000+ professionals in our courses here 👉 link.xelplus.com/yt-d-all-cou...
Quickly learn how to work with Excel VBA IF, THEN, ELSE, ELSEIF, AND statements. This way you can write Excel macros that are dependent on multiple conditions.
⬇️ Download the workbook here: pages.xelplus.com/vba-if-file
🔍 What You'll Learn:
- Fundamentals of IF Statements: Understand the basics of using IF statements in Excel VBA for condition-based actions.
- Practical Applications: Learn to apply IF statements to single cells and ranges, incorporating logical operations like AND and OR.
- Enhanced Data Manipulation: Discover how to dynamically highlight cells, automate calculations, and transform data using IF statements.
- Advanced Techniques: Dive deeper into ELSEIF and ELSE, enabling more complex and nuanced decision-making in your macros.
We take a look at looping through a set range of cells in an Excel table, checking their value and then changing the cell color based on that value.
In addition to learning the IF THEN statement and how to loop through cells, you also learn how to quickly get the color code of a specific cell so you can refer to it in your Excel macro. I'll show you a trick with the immediate window and how you can test, and query code in there.
★ Links to related videos: ★
FOR EACH VBA: • Loop Through Cells Ins...
IF THEN in Excel Formulas: • Excel IF Formula: Simp...
VBA Playlist: • Excel VBA & Macros Tut...
★★ My Online Excel Courses including VBA ★★ www.xelplus.com/courses/
➡️ Join this channel to get access to perks: / @leilagharani
👕☕ Get the Official XelPlus MERCH: xelplus.creator-spring.com/
🎓 Not sure which of my Excel courses fits best for you? Take the quiz: www.xelplus.com/course-quiz/
🎥 RESOURCES I recommend: www.xelplus.com/resources/
🚩Let’s connect on social:
Instagram: / lgharani
LinkedIn: / xelplus
Note: This description contains affiliate links, which means at no additional cost to you, we will receive a small commission if you make a purchase using the links. This helps support the channel and allows us to continue to make videos like this. Thank you for your support!
#excel #ExcelVBA

Опубликовано:

 

22 авг 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 201   
@LeilaGharani
@LeilaGharani 5 месяцев назад
Grab the file I used in the video from here 👉 pages.xelplus.com/vba-if-file
@ken7439
@ken7439 2 года назад
The G.O.A.T online teacher. Thank you, Leila.
@sanjeevtyagi7471
@sanjeevtyagi7471 5 лет назад
You make any VBA code look so simple. I've always learnt something new from your videos. Thanks
@mobr.
@mobr. 5 лет назад
Thank you, your Excel VBA tutorial on IF THEN statements was clear, concise, and coherent.
@philipmcdonnell7168
@philipmcdonnell7168 5 лет назад
Well, you’ve done it again: I’ve never seen the Immediate window used to find a colour. Obvious really but so is everything once somebody has shown you the trick. Many thanks. 👍🏻🙄
@vijaygusain119
@vijaygusain119 3 года назад
I remember telling you that I cant understand VBA and today just because of you I am able to create logical templates using vba...Thanks Leila! I cud never have Guru like you!
@NassC-bi8pm
@NassC-bi8pm 3 года назад
I really appreciate your way of explanations, as you cover up all possible questions in the subject. You are my favourite xls teacher .
@foxbox7929
@foxbox7929 3 года назад
Finally, an actually good teacher! So glad to have you with us online!
@dyidata7930
@dyidata7930 5 лет назад
Great video on ifs and for loops. I have always used vbyellow and other colors. Awesome way to choose more color options. I learned something new.
@Omwereru
@Omwereru 3 года назад
Wow!..to say you are great in explanation, is an understatement!. This is by far, the best tutorial I have ever seen or heard!.Thank you very much!
@nsanerydah
@nsanerydah 4 года назад
While an older video, the value is still top-tier and has what I needed! Keep up the great work Miss!
@LeilaGharani
@LeilaGharani 4 года назад
Thank you! Will do!
@garyallan69
@garyallan69 5 лет назад
Love it. Thank you for explaining things so well
@christophersly8448
@christophersly8448 5 лет назад
One of the best instructors on the topic of VBA...huge thanks!!!
@LeilaGharani
@LeilaGharani 5 лет назад
Wow, thank you for the compliment Christopher!
@khaledenbaya6446
@khaledenbaya6446 5 лет назад
I don't find anything to say better than thank you very much from all of my heart
@Lookin4Reasons2Laugh
@Lookin4Reasons2Laugh 4 года назад
Gracious. Thank you. 2:47 in, and after an hour of searching the Internet, you helped me solve it in less than three. Boy.
@LeilaGharani
@LeilaGharani 4 года назад
Glad to help :)
@HoppiHopp
@HoppiHopp 5 лет назад
That's so elegant. I really like working with VBA and the proper Excel tables as a reference.
@LeilaGharani
@LeilaGharani 5 лет назад
Thank you! Agree - Excel table referencing does make things easier....
@1gopalakrishnarao
@1gopalakrishnarao 5 лет назад
Excellent. No words further to explain your presentation. Really MY EXCEL TEACHER IS A GENIUS. I AM VERY LUCKY TO SEE HER BLESSINGS IN EVERY VIDEO.
@LeilaGharani
@LeilaGharani 5 лет назад
Thank you very much Gopala for the very kind words and for your support.
@mchamis1
@mchamis1 5 лет назад
Very insightful. I think you're a genius. keep the videos coming.
@internet_wanderer8316
@internet_wanderer8316 4 года назад
Thanks. I really admire your ways to teach as I am able to replicate whatever you show in your videos. Thanks a lot.
@exceldashboardandvba2155
@exceldashboardandvba2155 5 лет назад
Good job Leila. Thank you for sharing.
@ckokse
@ckokse 5 лет назад
Brilliant, thanks for making VBA "digestable" even for me ;-)
@17aig
@17aig 5 лет назад
Thank you so much for your very super educated videos and so clearly explained
@poultryland2609
@poultryland2609 3 года назад
Hats off to Leila gharani, very informative channel
@dslaugh46544
@dslaugh46544 4 года назад
Love the classic Leila. Beautiful and smart. If only I knew half the stuff you make look so easy lady. Thank you.
@LeilaGharani
@LeilaGharani 4 года назад
Thank you, Dan! 😊
@kossiviaglee2997
@kossiviaglee2997 3 года назад
Thanks, please don't stop!
@samuelprosper2699
@samuelprosper2699 5 лет назад
Amazing. Thanks for the knowledge shared on VBA!!
@LeilaGharani
@LeilaGharani 5 лет назад
You're very welcome Samuel!
@funniq
@funniq 5 лет назад
Great video again ... I LOVE the trick you showed on 8:46 .... very handy ...thanks for everything
@MyChannel706
@MyChannel706 Месяц назад
Yup - best instructor. Thank you for this video!
@LeilaGharani
@LeilaGharani Месяц назад
Wow, thanks!
@Lcmproenca
@Lcmproenca 2 года назад
Thanks a lot, that was just what I needed. Saved my life.
@AbdulRahman-hd6ju
@AbdulRahman-hd6ju 5 лет назад
I am waiting for this .. thank you ..
@JarlBalgruff_
@JarlBalgruff_ Год назад
Thank you very much for this VBA video, I learned a lot! I wish you received more views
@md.mahbubrahman7891
@md.mahbubrahman7891 5 лет назад
Really pleased to watch & learn new thinks.
@MrAkhantus
@MrAkhantus 3 года назад
every day, when i have a problem with excell, your videos helps me a lot. for example, you solved my last, and i won a beer :D THX Leila You are the best
@LeilaGharani
@LeilaGharani 3 года назад
Great to hear, Sándor!
@gregappelt
@gregappelt 5 лет назад
I like this method much better than conventional formatting rules.
@FranciscoPereiro
@FranciscoPereiro 5 лет назад
Amazing channel. Got me hooked, I'm learning a lot. Keep it up...
@LeilaGharani
@LeilaGharani 5 лет назад
I'm glad you like the content here :)
@wayneedmondson1065
@wayneedmondson1065 5 лет назад
Hi Leila.. an excellent and informative tutorial, as always.. thanks and Thumbs up!
@LeilaGharani
@LeilaGharani 5 лет назад
Thank you Wayne!
@sukhmaidickoff
@sukhmaidickoff 4 года назад
Wow...you´re very skilled at this and explaining it in a way so it´s easy to understand.
@LeilaGharani
@LeilaGharani 4 года назад
Glad you find the tutorial helpful Bryan.
@akmaldurrani4616
@akmaldurrani4616 Год назад
This is really helpful thank!
@ajexcel
@ajexcel 5 лет назад
Thanks! Leila that's really useful video in the context of VBA...appreciate your efforts a lot which really help us to learn excel quite easily. I always eagerly waiting for your video coz it always has something new to learn...i am excited about VBA will wait more video on VBA. Thanks a lot.👏👏👍👍☺
@LeilaGharani
@LeilaGharani 5 лет назад
Thank you Ajay! Optimally I'd love to be able to upload 2 videos per week. 1 for VBA and the other Excel. But unfortunately I can't find the time for that (yet)...so for now I'll try to get in one a month. Thank you for your support.
@stevennye5075
@stevennye5075 3 года назад
Excellent work!
@timwills6584
@timwills6584 4 года назад
Excellent! Clear, to the point, and easy to understand...... Just what I needed :)
@LeilaGharani
@LeilaGharani 4 года назад
I'm glad to hear that Tim.
@timwills6584
@timwills6584 4 года назад
@@LeilaGharani Subscribed. I'll be back for more :)
@saj1507
@saj1507 5 лет назад
perfect explanation in simplest manner.
@LeilaGharani
@LeilaGharani 5 лет назад
Glad you like it.
@mundonemesis
@mundonemesis 5 лет назад
This was awesome and really helpfull, Thank you.
@LeilaGharani
@LeilaGharani 5 лет назад
You're very welcome. Glad you like it.
@krn14242
@krn14242 5 лет назад
I agree with Mike Awesome. Especially liked the method you use to determine color numbers. Great tip.
@LeilaGharani
@LeilaGharani 5 лет назад
Thanks! I'm glad you like that tip. That's saved me a lot of time figuring out the right color in the code.
@krn14242
@krn14242 5 лет назад
Yes, it also opens up ALL color possibilities and not be restricted to vbgreen or vbred :)
@byronstutorialspage2134
@byronstutorialspage2134 5 лет назад
Awesome, I learned three things I didn't already know. (I already knew how to do IF in VBA :) 1. vba.colorconstants (my new favourite code) 2. query a cell colour from the Immediate Window (so very very cool) 3. elseif (gonna have fun playing with that one!) I am one of a very small group of Excel gurus (3 of us) in my workplace, I spend a lot of time trying to explain Excel to people who don't even know how to hide gridlines (urrrrgh).... now I just send them to your RU-vid Channel and tell them to come see me if they still can't do what they want! BEST TUTORIAL VIDEOS EVER FOR EXCEL!!! Cheers, -Byron
@mimicba1114
@mimicba1114 4 года назад
Thank you ..... was clear !!!
@satishgopal2406
@satishgopal2406 5 лет назад
Thank you🙏
@allabout1135
@allabout1135 5 лет назад
Wow. Leila. Wow this was brillant. Thanks!
@LeilaGharani
@LeilaGharani 5 лет назад
I'm glad you like it Aleksandrs! Thanks for watching.
@robertakwasiadjei8223
@robertakwasiadjei8223 5 лет назад
Thanks a Lot
@amitkalra8774
@amitkalra8774 5 лет назад
Nicely done
@vida1719
@vida1719 5 лет назад
Very well explained. It's a good idea to convert data set into table and use this in VBA code
@LeilaGharani
@LeilaGharani 5 лет назад
Thanks. Agree - it makes range referencing a little easier...
@mikeponzio9996
@mikeponzio9996 5 лет назад
Always informative, great info! Thanks for putting the excel language in "Plain English" :-)
@LeilaGharani
@LeilaGharani 5 лет назад
You're welcome Mike. Thanks for watching :)
@mikeponzio9996
@mikeponzio9996 5 лет назад
Leila Gharani is the online course going to be updated anytime soon? In an app crazy world, I just want to make sure it doesn’t get upgraded after I would purchase.
@jorgelopes4559
@jorgelopes4559 5 лет назад
Thanks. It's great.
@noonely
@noonely 3 месяца назад
Wonderfull explanation ❤
@paulj625
@paulj625 2 года назад
GOAT indeed!!!
@regisaguas8579
@regisaguas8579 5 лет назад
Thanks again
@ismailismaili0071
@ismailismaili0071 5 лет назад
Hi Ms. Leila thank you so much i'm so sorry i know i missed 3 videos but I really was so busy. anyway thanks again for your videos.
@LeilaGharani
@LeilaGharani 5 лет назад
No worries Ismail! Thanks for your support - anytime :)
@simonalqasab4301
@simonalqasab4301 Год назад
You deserve a like
@LeilaGharani
@LeilaGharani Год назад
Thanks!
@user-km8nn6br8y
@user-km8nn6br8y 6 месяцев назад
thank you very much
@alttab157
@alttab157 4 года назад
thank you maam for this very informative video. and by the way i bought 2 of your courses in UDEMY :D and now i'm in progress :D
@samikacimi6858
@samikacimi6858 2 года назад
you are the best
@iqbaluk
@iqbaluk 4 года назад
Excellent,
@nirmalkumar-fh3yg
@nirmalkumar-fh3yg 3 года назад
Best understanding in IF statement in VBA with color coding.
@mmahgoub1530
@mmahgoub1530 4 года назад
Thank You
@magicassassin1947
@magicassassin1947 3 года назад
I'm very huge fan of using vba 😍😍
@LeilaGharani
@LeilaGharani 3 года назад
👍
@puthuval1
@puthuval1 5 лет назад
many thanks,
@francescmulleratmarimon6576
@francescmulleratmarimon6576 3 года назад
You are amazing! Saved my task for the day. +1 Sub
@LeilaGharani
@LeilaGharani 3 года назад
Thanks for the sub!
@walek2001
@walek2001 5 лет назад
thank you!
@LeilaGharani
@LeilaGharani 5 лет назад
You're welcome Damian :)
@srisureshm1476
@srisureshm1476 4 года назад
Good one
@sandeepkothari5000
@sandeepkothari5000 5 лет назад
Great!
@mmahgoub1530
@mmahgoub1530 4 года назад
very nice
@osoriomatucurane9511
@osoriomatucurane9511 Месяц назад
Absolutely awesome tutorial, aggretating valuable tricks in most clear, concise and coherent fashion. Just wondering if using named range wouldnt be straitforward referencing the range than getting the synthax of the table column. Just learning and falling in love with xls out of your tutorials along with other top excel talented brilhant minds who are truly committed to unveil the power of Excel just like excellisfun and teachexcel.
@alializadeh8195
@alializadeh8195 Год назад
Thank ya
@TheZuge2877
@TheZuge2877 2 года назад
¡Gracias!
@LeilaGharani
@LeilaGharani 2 года назад
Thank you!
@vijaysahal4556
@vijaysahal4556 4 года назад
hii madam really so gud ur if statement in vba m loving it
@LeilaGharani
@LeilaGharani 4 года назад
I'm glad to hear that Vijay.
@hosseinhosseinpoor4845
@hosseinhosseinpoor4845 3 года назад
thanks.
@gromitj
@gromitj 3 года назад
Clean and helpful video, but I've found referencing cells on different sheets somewhat of a nightmare recently. It would be great if guides provided a full reference to the cells being manipulated without Activating the desired sheet.
@parlin4556
@parlin4556 5 лет назад
cool! thanks..
@LeilaGharani
@LeilaGharani 5 лет назад
You're welcome. Glad you like it.
@siddharthsatbhadre
@siddharthsatbhadre 2 года назад
Thanks mam 🙏🙏🙏🙏🙏🙏
@LeilaGharani
@LeilaGharani 2 года назад
My pleasure :)
@szimnave
@szimnave 5 лет назад
hello leila your tutorial is really awesome!! btw can i use excel formulas in VBA?
@joseantonioperez8273
@joseantonioperez8273 5 лет назад
Hi Leila Nice video do you ha some examples using a command or function like do while [condition] or loop to be interrupted by pressing specific key or button? If you do it will be very appreciated if you share have a nice day😍😍
@firasqatouni4605
@firasqatouni4605 4 года назад
Great work. If I may ask for a VBA that changes cell color based on a specific text in a cell, not based on the cell value.
@michaeldiamond2726
@michaeldiamond2726 5 лет назад
HI Leiia, I really like your approach on this. This video isn't part of the course, an addition to it. I think it would be cool if you could have future VBA videos on obscure macros that you couldn't find on many websites. Chip Pearson has a lot of code on his site, I wonder if there are others that have code that could really be complex - like the ones you helped me with while I was at CTA earlier in the year. That macro was quite masterful and really cool. All the Best, Michael
@LeilaGharani
@LeilaGharani 5 лет назад
Hi Michael - Thank you! I revised it for RU-vid. I brought in different concepts from different lectures to one video. It's a good idea to show similar macros like the CTA one - actually I included the code I sent for that one in the VBA course.
@michaeldiamond2726
@michaeldiamond2726 5 лет назад
Really cool. I thought that import code in your course looked familiar though it has some minor tweaks to it. Look forward to m,ore videos.
@michaeldiamond2726
@michaeldiamond2726 5 лет назад
HI Leila, Is this part of your VBA course or an addition. I remember you went over it quite thoroughly but I'm not sure, Michael
@redhaakhund1271
@redhaakhund1271 3 года назад
Thanks for the video. how to add a blinking to it. Plz advise. Thanks
@i-cyril
@i-cyril 4 года назад
thank you i have a question. How do you apply this to copying and pasting of data from one sheet to another sheet
@hmcustomthreads2460
@hmcustomthreads2460 4 года назад
Great video! I am not entirely sure this is what I need but I need some assistance in a situation on Excel and I am wondering if you could help?
@jackzouyuquan9094
@jackzouyuquan9094 3 года назад
I have learnt macro from you. I like it. But let me know how you get the numbers for colours??
@amintaleghani2110
@amintaleghani2110 4 года назад
@ Leila Gharani, Thank you very much for your very helpful video. If I what this VBA codes to work automatically while the data are entered in the table what needs to be done?
@levitav
@levitav 5 лет назад
...Gracias
@LeilaGharani
@LeilaGharani 5 лет назад
Con mucho gusto :)
@inventoryoptimizationpro
@inventoryoptimizationpro Год назад
Hi Leila, Thank you for the tutorial. I'd like to ask you another question. How do you ask Excel to look for a month and start a sequence function at the month? I want a number to appear in every other column 6 times and start at the month I asked, for example. I am able to get the number to appear every other month 6 times using the sequence function, but I need help to get it to start at the month I want. If I drag my current formula across the column, it will interfere with the sequence function. Many thanks! Sharon
@michaelmoke5174
@michaelmoke5174 Год назад
Hi Leila, really like your videos about VBA. Excessing your videos from Papua New Guinea. My Question. I am trying to load tags to PI Process Book (PI SMT) but couldn't. Could you please show some light on this? Would really appreciate that.
@philipclarke6277
@philipclarke6277 5 лет назад
I use an spreadsheet to estimate jobs. I want to produce a PDF summary report from the spreadsheet data. Spreadsheet Column 1 is “Category” (eg: Building, Painting), Column 2 is “Description”, Column 6 is “Value”. The logic is to copy each row where Value is greater than zero (hide all other rows) and copy to new worksheet. Then print a PDF report grouping each category together and calculate the sub total for each category and with a grand total. I also want to auto size the rows and remove any blank rows and columns from the PDF report so I don't get multiple empty pages. Many thanks, Phil Category Description Value Building Build walls $200.00 Building Fix linings $300.00 Building Patch $400.00 Building Subtotal $900.00 Painting Paint walls $450.00 Painting Paint ceiling $250.00 Painting Paint doors $150.00 Painting Subtotal $850.00 Proposal Total $1,750.00
@indirayimsomboon4513
@indirayimsomboon4513 5 лет назад
Have you got video how to calculate tax on tax using Excel?
@tapsivamsi515
@tapsivamsi515 4 года назад
i tried the same code but its giving error as compile error: Else without if
@freemanwong911
@freemanwong911 9 месяцев назад
Very useful VBA code! Is it possible to put the condition of Range("B9").Value>0 and Range("B9").Value
@atifr
@atifr 2 года назад
Dear Leila, Nice video but what if i want to multiply 2 columns in a table with condition
@rolgom
@rolgom 3 года назад
Hello, am one of your avid follower and your explanations find me very easy to understand. Can you help me with my concern? I have 10 sets of data with column headings; Date, OR, Beg. Bal, Amt Due, Penalty, Discount, Amt Paid, End Bal and Deacription. Those 9 columns are repetitive across columns for like 10 sets. I only need to get Date, OR and Amt Paid, can you help me with this, thanks
@zozozozo43
@zozozozo43 5 лет назад
♥♥ Hope you're doing well! .... Here two suggestions: * Other way for choosing color, from Home Menu 'Fill Color > More Color > Custom' and take values of RGB * it will be good if we put 'With' statement: For Each cell In Range("TableSa.... With cell.Interior If cell > 0 And.... .Color = RGB(226, 107, 10) ElseIf ..... .Color ...... Else .Color ...... End If End With Next
@LeilaGharani
@LeilaGharani 5 лет назад
Thank you Assem. Agree - RGB is good too. WITH is also a good addition. Thank you for watching.
@zozozozo43
@zozozozo43 5 лет назад
You're very welcome Leila, by the way , I have some ideas, if you want to produce them in Videos, I will send you lectures with details and you can produce them by your own way, if you agree let me know. your email is info@xelplus.com ?
@saugataghosh2448
@saugataghosh2448 Месяц назад
Need help with vba. Have Employee names in Column A, have date & time stamps in column B, have Entry or exit written in column C. Need a code that will calculate the actual time in office which is total time minus sum of all breaks. There are multiple entries and exits in one day for each employee. They also work overnight.
Далее
How to Create & Use Excel Macros (Real world example)
10:09
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
How to get the Last Row in VBA(The Right Way!)
15:41
Просмотров 153 тыс.
3 Simple Tips for Looping Cells in VBA for Excel
8:02
10x your productivity with these AI tools in Excel 😲
18:42
When You Should Use the New Excel LET Function
17:18
Просмотров 756 тыс.
VBA For Loop - A Complete Guide
12:36
Просмотров 79 тыс.