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

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ •

  • @LeilaGharani
    @LeilaGharani  10 місяців тому +1

    Grab the file I used in the video from here 👉 pages.xelplus.com/vba-if-file

  • @ken7439
    @ken7439 3 роки тому +6

    The G.O.A.T online teacher. Thank you, Leila.

  • @vijaygusain119
    @vijaygusain119 4 роки тому +1

    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!

  • @sanjeevtyagi7471
    @sanjeevtyagi7471 6 років тому +12

    You make any VBA code look so simple. I've always learnt something new from your videos. Thanks

  • @foxbox7929
    @foxbox7929 4 роки тому +8

    Finally, an actually good teacher!
    So glad to have you with us online!

  • @philipmcdonnell7168
    @philipmcdonnell7168 6 років тому +4

    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. 👍🏻🙄

  • @1gopalakrishnarao
    @1gopalakrishnarao 6 років тому

    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  6 років тому

      Thank you very much Gopala for the very kind words and for your support.

  • @tutorials--1234
    @tutorials--1234 6 років тому +1

    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 UA-cam 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

  • @mobr.
    @mobr. 5 років тому +3

    Thank you, your Excel VBA tutorial on IF THEN statements was clear, concise, and coherent.

  • @christophersly8448
    @christophersly8448 5 років тому

    One of the best instructors on the topic of VBA...huge thanks!!!

    • @LeilaGharani
      @LeilaGharani  5 років тому +1

      Wow, thank you for the compliment Christopher!

  • @nsanerydah
    @nsanerydah 4 роки тому

    While an older video, the value is still top-tier and has what I needed! Keep up the great work Miss!

  • @NassC-bi8pm
    @NassC-bi8pm 4 роки тому +1

    I really appreciate your way of explanations, as you cover up all possible questions in the subject. You are my favourite xls teacher .

  • @poultryland2609
    @poultryland2609 4 роки тому

    Hats off to Leila gharani, very informative channel

  • @HoppiHopp
    @HoppiHopp 6 років тому

    That's so elegant. I really like working with VBA and the proper Excel tables as a reference.

    • @LeilaGharani
      @LeilaGharani  6 років тому +1

      Thank you! Agree - Excel table referencing does make things easier....

  • @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.

  • @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.

  • @MrAkhantus
    @MrAkhantus 4 роки тому

    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

  • @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!

  • @JarlBalgruff_
    @JarlBalgruff_ Рік тому

    Thank you very much for this VBA video, I learned a lot! I wish you received more views

  • @dyidata7930
    @dyidata7930 6 років тому +1

    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.

  • @Lcmproenca
    @Lcmproenca 3 роки тому

    Thanks a lot, that was just what I needed. Saved my life.

  • @kossiviaglee2997
    @kossiviaglee2997 4 роки тому

    Thanks, please don't stop!

  • @saj1507
    @saj1507 5 років тому

    perfect explanation in simplest manner.

  • @magicassassin1947
    @magicassassin1947 3 роки тому

    I'm very huge fan of using vba 😍😍

  • @freemanwong911
    @freemanwong911 Рік тому +1

    Very useful VBA code! Is it possible to put the condition of Range("B9").Value>0 and Range("B9").Value

  • @nirmalkumar-fh3yg
    @nirmalkumar-fh3yg 4 роки тому

    Best understanding in IF statement in VBA with color coding.

  • @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.

  • @timwills6584
    @timwills6584 5 років тому

    Excellent! Clear, to the point, and easy to understand...... Just what I needed :)

    • @LeilaGharani
      @LeilaGharani  5 років тому +1

      I'm glad to hear that Tim.

    • @timwills6584
      @timwills6584 5 років тому

      @@LeilaGharani Subscribed. I'll be back for more :)

  • @md.mahbubrahman7891
    @md.mahbubrahman7891 5 років тому

    Really pleased to watch & learn new thinks.

  • @khaledenbaya6446
    @khaledenbaya6446 6 років тому

    I don't find anything to say better than thank you very much from all of my heart

  • @mchamis1
    @mchamis1 6 років тому

    Very insightful. I think you're a genius. keep the videos coming.

  • @MyChannel706
    @MyChannel706 5 місяців тому

    Yup - best instructor. Thank you for this video!

  • @osoriomatucurane9511
    @osoriomatucurane9511 6 місяців тому

    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.

  • @stevennye5075
    @stevennye5075 3 роки тому

    Excellent work!

  • @gregappelt
    @gregappelt 6 років тому

    I like this method much better than conventional formatting rules.

  • @akmaldurrani4616
    @akmaldurrani4616 Рік тому

    This is really helpful thank!

  • @17aig
    @17aig 6 років тому

    Thank you so much for your very super educated videos and so clearly explained

  • @paulj625
    @paulj625 3 роки тому +1

    GOAT indeed!!!

  • @krn14242
    @krn14242 6 років тому

    I agree with Mike Awesome. Especially liked the method you use to determine color numbers. Great tip.

    • @LeilaGharani
      @LeilaGharani  6 років тому

      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 6 років тому

      Yes, it also opens up ALL color possibilities and not be restricted to vbgreen or vbred :)

  • @vida1719
    @vida1719 6 років тому

    Very well explained. It's a good idea to convert data set into table and use this in VBA code

    • @LeilaGharani
      @LeilaGharani  6 років тому

      Thanks. Agree - it makes range referencing a little easier...

  • @exceldashboardandvba2155
    @exceldashboardandvba2155 6 років тому

    Good job Leila. Thank you for sharing.

  • @wayneedmondson1065
    @wayneedmondson1065 6 років тому

    Hi Leila.. an excellent and informative tutorial, as always.. thanks and Thumbs up!

  • @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

  • @funniq
    @funniq 5 років тому

    Great video again ... I LOVE the trick you showed on 8:46 .... very handy ...thanks for everything

  • @allabout1135
    @allabout1135 6 років тому

    Wow. Leila. Wow this was brillant. Thanks!

    • @LeilaGharani
      @LeilaGharani  6 років тому

      I'm glad you like it Aleksandrs! Thanks for watching.

  • @noonely
    @noonely 8 місяців тому

    Wonderfull explanation ❤

  • @simonalqasab4301
    @simonalqasab4301 2 роки тому

    You deserve a like

  • @ismailismaili0071
    @ismailismaili0071 6 років тому

    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  6 років тому

      No worries Ismail! Thanks for your support - anytime :)

  • @ajexcel
    @ajexcel 6 років тому

    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  6 років тому

      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.

  • @ckokse
    @ckokse 6 років тому +3

    Brilliant, thanks for making VBA "digestable" even for me ;-)

  • @redhaakhund1271
    @redhaakhund1271 3 роки тому

    Thanks for the video. how to add a blinking to it. Plz advise. Thanks

  • @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.

  • @gromitj
    @gromitj 4 роки тому +2

    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.

  • @mimicba1114
    @mimicba1114 5 років тому

    Thank you ..... was clear !!!

  • @jackzouyuquan9094
    @jackzouyuquan9094 4 роки тому

    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?

  • @samuelprosper2699
    @samuelprosper2699 5 років тому

    Amazing.
    Thanks for the knowledge shared on VBA!!

  • @mikeponzio9996
    @mikeponzio9996 6 років тому

    Always informative, great info! Thanks for putting the excel language in "Plain English" :-)

    • @LeilaGharani
      @LeilaGharani  6 років тому

      You're welcome Mike. Thanks for watching :)

    • @mikeponzio9996
      @mikeponzio9996 6 років тому

      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.

  • @firasqatouni4605
    @firasqatouni4605 4 роки тому +1

    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.

  • @FranciscoPereiro
    @FranciscoPereiro 6 років тому

    Amazing channel. Got me hooked, I'm learning a lot. Keep it up...

    • @LeilaGharani
      @LeilaGharani  6 років тому +1

      I'm glad you like the content here :)

  • @samikacimi6858
    @samikacimi6858 3 роки тому

    you are the best

  • @iqbaluk
    @iqbaluk 5 років тому

    Excellent,

  • @srisureshm1476
    @srisureshm1476 5 років тому

    Good one

  • @garyallan69
    @garyallan69 6 років тому

    Love it. Thank you for explaining things so well

  • @michaeldiamond2726
    @michaeldiamond2726 6 років тому

    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  6 років тому

      Hi Michael - Thank you! I revised it for UA-cam. 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 6 років тому

      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.

  • @robertakwasiadjei8223
    @robertakwasiadjei8223 6 років тому +2

    Thanks a Lot

  • @atifr
    @atifr 3 роки тому

    Dear Leila,
    Nice video but what if i want to multiply 2 columns in a table with condition

  • @zozozozo43
    @zozozozo43 6 років тому

    ♥♥ 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  6 років тому +1

      Thank you Assem. Agree - RGB is good too.
      WITH is also a good addition. Thank you for watching.

    • @zozozozo43
      @zozozozo43 6 років тому

      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 ?

  • @francescmulleratmarimon6576
    @francescmulleratmarimon6576 4 роки тому

    You are amazing! Saved my task for the day. +1 Sub

  • @mmahgoub1530
    @mmahgoub1530 4 роки тому

    Thank You

  • @reeteshism
    @reeteshism 4 роки тому

    Hello there. Not sure whether this is the correct platform to ask this question, however was not able to find the video about the question which I'm going to ask.
    I'm trying to create a tracker on excel using VBA, which captures the "START TIME" and "END TIME" of a specific task.
    The tracker is almost complete. The only thing where I'm getting stuck is on the message box command.
    Suppose, there are 2 buttons "START TIME" & "END TIME". Obviously if you click on "START TIME" Marcos will record the current time and when you click on "END TIME" macros will end the task, record the time and will give the difference between the 2 times recorded. If without clicking on the "START TIME" button someone clicks on "END TIME", they will get a message box which says "Task Not Started".
    However, if a task is already started and ongoing and instead of clicking on "END TIME" to stop the task, the person clicks on "START TIME" again, it starts a new task and the old one doesn't end. To stop it, we'll have to click on START TIME twice, so that it can end the previous task and also the new one which started.
    If you could help me with the VBA Coding where in I'll be able to get a message box which says "End Previous Task", if someone clicks on "START TIME' again instead of clicking on "END TIME" to stop the ongoing task.
    Or copy the url of the video if you already have discussed this on any of your videos
    Thanks

  • @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

  • @mmahgoub1530
    @mmahgoub1530 4 роки тому

    very nice

  • @vijaysahal4556
    @vijaysahal4556 5 років тому

    hii madam really so gud ur if statement in vba m loving it

  • @madalindombrovschi7002
    @madalindombrovschi7002 3 роки тому

    Hello Leila,
    I do have a question here, i'm trying to create a formula or condition like this " If cell A start with letter " F " then cell B should start with letter " K " else " ERRORR ". Do you have any idea how can i do that ?
    Thank you.

  • @inventoryoptimizationpro
    @inventoryoptimizationpro 2 роки тому

    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

  • @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?

  • @eikky2
    @eikky2 7 місяців тому

    Good after noon Madam,
    What would be the formula if i have to loop across the the row rather than down the column. Still you using the formula of "if and"
    here is my case i have the following formula:
    Sheets("Progress").Select
    Dim e As Double
    e = 5
    For Each cell In Range("aB5:ku40")
    If cell.Value = Cells(e, 28).Value Then
    Cells(e, 28).Value = (Cells(e, 1))

    Else
    Cells(e, 28).Value = ""

    End If
    e = e + 1
    Next cell
    i want the formula to run throught row than the Column.

  • @MrWmo1975
    @MrWmo1975 2 роки тому

    Hi Leila, could you please help me?
    I have a spreadsheet where I have a drop down menu in column B and If the user selects ‘operator1’ or ‘operator2’ i would like multiple cells (F-L, Z-AC, AF-AM & Az) on the same row to be populated with ‘N/A’

  • @TheZuge2877
    @TheZuge2877 3 роки тому

    ¡Gracias!

  • @mundonemesis
    @mundonemesis 5 років тому

    This was awesome and really helpfull, Thank you.

    • @LeilaGharani
      @LeilaGharani  5 років тому

      You're very welcome. Glad you like it.

  • @amitkalra8774
    @amitkalra8774 6 років тому

    Nicely done

  • @satishgopal2406
    @satishgopal2406 6 років тому +1

    Thank you🙏

  • @jorgelopes4559
    @jorgelopes4559 6 років тому

    Thanks. It's great.

  • @dougls2564
    @dougls2564 Рік тому

    Hello, I hope you are well. I have a question that I can not find the answer and I hope you can help. In your example "For x = 1 to 10". What if I wanted to be able to change the " 10 " element But from the excel main sheet1. I am thinking like I would enter a value in a cell and the loop would run that many times. Or maybe a pull down or something. My for x = 1 to ??? will change and I would like to not open the editor every time. Just entering it on the sheet somehow would be helpful. Any suggestions? Thank you

  • @siddharthsatbhadre
    @siddharthsatbhadre 3 роки тому

    Thanks mam 🙏🙏🙏🙏🙏🙏

  • @alializadeh8195
    @alializadeh8195 2 роки тому

    Thank ya

  • @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

  • @indirayimsomboon4513
    @indirayimsomboon4513 5 років тому

    Have you got video how to calculate tax on tax using Excel?

  • @AbdulRahman-hd6ju
    @AbdulRahman-hd6ju 6 років тому

    I am waiting for this .. thank you ..

  • @saugataghosh2448
    @saugataghosh2448 5 місяців тому

    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.

  • @harikishore7095
    @harikishore7095 4 роки тому

    Awesome Video... And Nice Learning.... Do you have video for the below mentioned reason
    1. Multiple If's and Else If's - with a validation sub
    2. If any of the if's fail, it shouldn't call another macro that I have
    3. All the errors needs to be corrected, before it calls another macro
    Please help!

    • @LeilaGharani
      @LeilaGharani  4 роки тому

      Thank you. I cover this in detail in my complete course. Not sure if I have a video on it here. Check out the VBA playlist.

  • @hosseinhosseinpoor4845
    @hosseinhosseinpoor4845 3 роки тому

    thanks.

  • @joseantonioperez8273
    @joseantonioperez8273 6 років тому

    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😍😍

  • @willyaguinaldo4778
    @willyaguinaldo4778 2 роки тому

    what code for not accepting negative value.Thanks

  • @vishurakeshrego
    @vishurakeshrego 4 роки тому

    I have a row with negative & Positive Values in Multiple Columns. How do I hide the Columns with Negative Values

  • @EcostellaHome
    @EcostellaHome 2 місяці тому

    VBA module doesn't come up for me. Also, I need to do this for a table with words, not letters.

  • @vinod4198
    @vinod4198 4 роки тому

    Hi can you please tell me how to open a active X in Microsoft 2011 in mac

  • @szimnave
    @szimnave 5 років тому

    hello leila your tutorial is really awesome!! btw can i use excel formulas in VBA?

  • @saugataghosh2448
    @saugataghosh2448 5 місяців тому

    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