How to Declare (Dim) and Set VBA Variables (use data types correctly)

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

КОМЕНТАРІ • 110

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

    Get access to the full Excel VBA course here: www.xelplus.com/course/excel-vba-excel-macros/

  • @dschulz5647
    @dschulz5647 5 років тому +4

    This helped explain a bunch for me. Usually videos don't help much when it comes to coding but this was actually very helpful. Thank you!

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

    Another great video! Dim, Set and such have been the bane of my existence, so It's good to have it explained clearly. I'll be watching this a couple more times, just to be sure I really get a grasp on it! (People have tried to explain these to me before, but they get into too much "tech jargon" that makes my brain spin around, LOL!)
    Thank you!

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

      I'm glad this video helps :) Thank you for your support Jenny.

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

      Can you please tell me DIM Full Form

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

    During such lock down, watching such easy explanation of tough topic is awesome..
    U r up to the point and so clear, and same time so easy......

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

    Hi Leila, a minor correction:
    The largest positive number that the INTEGER data type can hold is not: 32768 but: 32767.
    Thank you for your excellent videos 🙂

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

    Very informative, waiting some more Videos on the VBA, eagerly. Your Explanation is Excellent, and crystal clear.

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

      Thank you very much Gopala! Very happy to hear you like the VBA series. I will be alternating between Excel and VBA in the next weeks :)

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

    Thanks for the great Data Type video!!

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

      You're very welcome Mike :) Thank you for your support.

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

    I have multiple disabilities and health problems. In my sixties now and lost my job because of them......but a love of Excel makes me want to learn vba. I recorded a macro that "Cleared Content" from multiple non contiguous Ranges. I went into gab to run it but kept getting an error at lines of code starting with "Union Range." Can't understand it. Is it simple to rectify? Your channel is IMHO the best on You Tube for Excel. Well explained. Great examples and explanations. Superb. Thank you very much

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

      Make sure you didn't record in relative mode. If you go to the developer tab make sure the "use relative reference" toggle is off. If these ranges are fixed ranges, it would be best to get direct references - otherwise you could run into errors.

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

    superb. i like the way you touch every small point while explaining.

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

      Thank you! Glad you like the explanation.

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

    Thank you. Your vba and excel courses are excellent.

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

    Intriguing rabbit hole I have stumbled upon.

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

    Thank you for the error example. That has been frustrating to work through and your explanation is very helpful.

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

      You're very welcome. I'm glad to hear the explanation was helpful.

  • @naheda.ikhtier6596
    @naheda.ikhtier6596 3 роки тому

    Your every video is very helpful 😊😊

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

    Your tutorials are very good. thank you.

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

    oh! Just the info I was looking for. Now my macro works! Thanks.

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

    Thank you Leila. You are always amazing!

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

      You're very welcome Marcel. Thank you for dropping by :)

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

    Hi LEILA,
    Your video is very helpful and it is very clear to understand.
    Can you please help me with the following scenario:
    1) I have a workbook of sheet1 with two columns and a few rows.
    2) Applied filter for sheet1 data
    3) I have duplicated the sheet1 in the same workbook and renamed it as "Test"
    4) Deleted the duplicates in sheet2
    5) Now, I need your help in copying a cell value(the data is dynamic) of sheet2 and paste it in the filtered column of sheet1 so that I can write the comments beside the two columns of sheet1.
    **NOTE: DATA IS DYNAMIC
    The columns are as below:
    SHEET1:
    COLUMN-1 COLUMN-2
    abc apple
    abc windows
    123 android
    abc os
    b phone
    123 android
    abc blackberry
    abc apple
    b nokia
    abc lenovo
    SHEET2:
    COLUMN-1 COLUMN-2
    abc apple
    123 android
    b phone
    I need the final result like this in SHEET1
    COLUMN-1 COLUMN-2 COMMENT
    abc apple
    abc windows same as apple
    123 android
    abc os same as apple
    b phone
    123 android same as android
    abc blackberry same as windows
    abc apple same as apple
    b nokia same as phone
    abc lenovo same as apple
    IT WOULD BE REALLY HELPFUL IF YOU CAN GUIDE ME ASAP.

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

    Love your videos, they are clear and easy to understand. :D

  • @Trendinvideowalasam
    @Trendinvideowalasam 5 років тому +2

    This video is good.in some videos of others I saw no dim is used in the beginning.
    Can u define all the codes why it is used for and when with elaboration.

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

      Check this too
      ua-cam.com/users/ExcelAutomationByMudit

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

    Very Informative & useful. Thank you for uploading & expecting more.

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

    Hi Leila,
    I'm currently your student using Udemy Business. And I feel I'm lucky to get enrolled with an excellent teacher. I couldn't figure out how to send you a query in Udemy and hence ended up searching for you here and would ask one. I have currently completed lecture 35 that speaks abt declaring variables. I'm unable to understand why do we beed variables? Is it necessary to have variables? What are variables? And can't I do without them in vba. I am a novice and have seen many codes and most of them have variables. But I always had these questions in my mind. I have googled alot, but nothing has solved this question yet.
    Please reply.

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

      If you do not declare variables it usually consumes much more memory and making your code slower. Also, it makes it easier to refer to it later.

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

      @@LeilaGharani I sincerely appreciate you taking out time and replying to me. Kudos to you. I'll keep this point in mind and proceed with the course. May be it doesn't make sense to me right now, but later it may. You've been an excellent presenter and tutor. And I trust you for that.

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

    Useful and clear as always, I love

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

    I can easily remember what you teach. Thanks a lot.

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

      Thank you! I'm glad to hear that Vivek :)

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

    Explained in systematic way

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

      Thank you. Glad you like it Uday.

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

    Die Übersicht ist extrem hilfreich! ☺️

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

      Freut mich. Vielen Dank.

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

      I heard you speaking German in one of the lectures in your "Unlock Excel VBA and Excel Macros" course (3/16) when you explained the syntax of the object model etc. and I was tempted :)

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

      :) I live in Austria.

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

    thank you so much Ms. Leila I wish you could do more videos because i really want to learn VBA

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

      I'll do my best :) it's not easy to get in more than 1 video per week. I'll alternate between usual Excel and VBA....

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

    Thank you, very helpful

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

    Thanks for such a basic concept sharing,

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

    Thank you very much Leila!

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

      You're very welcome. Hope it will come in handy.

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

    LET used in old BASIC programming language. I remembered it first time i saw Spectrum's Sinclair Basic

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

    Amazing tutorials

  • @255205titel
    @255205titel 5 років тому

    Thanks Leila, helps me a lot!

  • @BrPalavraCristã
    @BrPalavraCristã 3 роки тому

    I appreciate it thank you very much

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

    Thanks you for the information

  • @abdallah.kandiel
    @abdallah.kandiel 6 років тому

    This is an amazing video
    Welcome
    And happy thursday ur highness

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

      Happy Thursday :) You're very welcome. Hope your workload is better this week....

    • @abdallah.kandiel
      @abdallah.kandiel 6 років тому

      Leila Gharani it is
      Thanks 4 asking
      This is so kind if you
      But lucky me . If you know about fasting and ramadan month
      We are in holly month
      any way i like to share with you
      Our lovely istructor

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

    good review!

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

    Awesome.

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

    Well explained.....

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

    Thank you

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

    You are amazing...

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

    Really Amazing

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

      I'm glad you like it. Thank you for your support.

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

    Thankyou

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

    The only problem with it is that text you are typing fades away while you are typing, please fix it, your lectures are superb

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

    So could you please let us know the usage of "new" keyword, as far as i understood "new" keyword is used to instantiate object variables. Thanks in advance !

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

    I am going through all your session even i do macro coding intermediate level.. having one suggestion if you give session number for each lesson ..make it more easily for us to gone through

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

      Thank you for the suggestion. I've included them in a playlist so they can be viewed in order....

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

      Leila Gharani
      Thank you Leila...can you put a lesson for ms access and excel marco .
      How to transfer data from excel to access and how to use query for fetching data from access.
      I hope that would be useful for many people..

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

    Hi madam can you please do videos on averageif using vba in which user changes data every time it automatically updates.

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

    thanks thanks thanks

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

    Good👍

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

    10/10

  • @roberto-martins
    @roberto-martins 5 років тому

    Thanks.

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

    Thank you Leila....!! Can we have more videos on VBA

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

      You're very welcome. Yes - I will be alternating between VBA, charts, formulas etc....

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

      Thank u.. Leila

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

    Can I use the set statement at the module level? I have declared many variables as sheets and don't want to have to set them in every sub() I have in the same module. thank you

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

    Thanks Leila :) :)

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

    Helpful :)

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

    Helpful

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

    Leila, Thanks for sharing.
    I've question in your example of LastRow=Rows.count what if it is not declared no Dim direct LastRow...
    What problem will it cause?

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

      If you don't declare it, your macro will still run without problems (as long as you don't have option explicit turned on) but declaring it makes it more efficient specially in terms of macro performance time....

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

      If the variable isn’t declared it will default as Variant, and will be less efficient (i.e. will use more memory)

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

    What will happen if I used integer data type for a data with a value of 32,769 or more?

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

    İn VBA round(10.25,1)=10.2 but in normal excel round(10.25,1)=10.3 I need calculate exactly in excel VBA. How can I round in VBA exactly? I need round(10.25,1)=10.3 in VBA

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

    Very good ese hi ielts ke bare mai b batayo

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

    hi , i am a beginner to vba macros, and want to get skilled in this field, i want to learn all the looping process and array......and charts with vba....could you please help....

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

      I have a section on arrays and charts inside the complete course. Feel free to check out the content (link is in the description of the video) to see if it covers the topics you're looking for.

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

    Hello
    I am trying to find an vba code to copy and paste every range of rows like(A1:C19).copy and paste in word file as image then copy from (A20:C39) and paste in the same word file and so on for the rest of the table in excel. they have told me that I need to use the looping in excel but I don't know exactly how to do it …. please help if you can

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

      I have a whole section (no 10) on Looping in my VBA course: courses.xelplus.com/p/excel-vba-excel-macros

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

    Cool thx

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

    Love u lots

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

    set is basically a setter and getter concept from oo programming I guess

  • @Pro-gamer_20108
    @Pro-gamer_20108 2 роки тому

    Hi looking code that help me to add cell data while we use send email cose

  • @60_daysff_per_year
    @60_daysff_per_year 3 роки тому

    You have to be careful when you use a long long variable.

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

    You are beautiful

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

    Good

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

    thanks