Excel VBA: Referring to Ranges & Writing to Cells (Range, Cells, Offset, Names)

Sdílet
Vložit
  • čas přidán 4. 07. 2024
  • Join 400,000+ professionals in our courses here 👉 link.xelplus.com/yt-d-all-cou...
    Explore the various methods to write to cells in Excel using VBA. Understand the nuances of using Range, Cells, Offset, and Defined Names for effective cell referencing.
    🎓 Get access to the full Excel VBA course here: www.xelplus.com/course/excel-...
    💡 Key Takeaways:
    ▪️ Different Referencing Methods: Learn various ways to target cells in Excel VBA for more precise control.
    ▪️ Practical Examples: Step-by-step demonstrations for each method.
    ▪️ Tips for Efficiency: Tips on how to optimize your VBA code for better performance.
    Referencing ranges is a common task in Excel VBA. It's important to be aware of the different ways you can write to Excel cells with VBA or macros. The macro recorder has its own preference when writing to ranges but it's not the only way.
    You'll be surprised at all the available options. Each method has its own advantages. They will become more obvious later on when you learn to loop inside a range in Excel.
    You'll learn how to use ranges, cells property, offset, named ranges, difference between activecell and selection, and how to reference entire rows or entire columns and also how to use autofit in Excel VBA.
    Practice along with me by opening up a blank Excel spreadsheet. Make sure you close other spreadsheets as we'll be writing to the active Workbook.
    Written Article: www.xelplus.com/vba-writing-t...
    This Excel VBA tutorial for beginners, is part of my "Unlock Excel VBA and Macros" course. Get it here: www.xelplus.com/course/excel-...
    0:00 - Introduction: Overview of cell referencing techniques in Excel VBA.
    0:56 - Creating a Module: Setting up for VBA coding.
    1:58 - Understanding Active Cell vs Selection: Clarifying key concepts.
    3:30 - Using Range and Cells Properties: Basic methods for cell referencing.
    6:54 - Advanced Referencing Techniques: Combining columns and rows.
    9:18 - Using the Offset Property: Shifting reference points.
    11:31 - Offset with Ranges: Applying offset to a range of cells.
    12:06 - Utilizing Name Manager: Assigning names for cell referencing.
    13:28 - Rows and Columns: Adjusting row heights and column widths.
    15:33 - Summary: Recap of all referencing methods.
    ★ Links to related videos: ★
    Learn about Visual Basic Editor: • Excel VBA tutorial for...
    Recording macros: • Excel VBA: Copy Data f...
    Properties & methods in VBA: • Learn How to Use Prope...
    ➡️ 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!
    #ExcelVBA

Komentáře • 263

  • @LeilaGharani
    @LeilaGharani  Před 5 měsíci

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

  • @TheDutchGemini
    @TheDutchGemini Před 2 lety +13

    VBA allows to specify ranges using the short notation with square brackets instead of the Range() or Cells() property. For instance 'Range("A1").Value' can be written in short as '[A1].Value'. This is also true when using areas, for instance [A2:C2].Value = "2nd", and named ranges such at [LastOne].Value = "10th".

  • @rag7628
    @rag7628 Před 5 lety +17

    Hello Leila, I've been working now through some of your great tutorials here and now I really have to make you a big compliment.
    Thanks sooooo much for the great work you a doing here, it's really a great performance.
    Your tutorials are very well structured and very easy to understand and extremely helpful. Thank You :-)

  • @dasrotrad
    @dasrotrad Před 6 lety +2

    This is really great Leila. Love your presentation and excellent explanations. It is very well thought out. You make it easy to understand. When Mike Girvin is following your videos, you know you are among the great. Thank you so much for sharing.

  • @Yolande26
    @Yolande26 Před 4 lety +5

    Leila has the best Excel tutorials/videos by far! I did two of her courses and she is simply the best instructor!

  • @chandrasekharboya8885
    @chandrasekharboya8885 Před 3 lety +4

    Hi Leila, Really really impressive explanation of cell referencing. This is the best video explaining the cell references.
    Thank you.

  • @ismailismaili0071
    @ismailismaili0071 Před 6 lety +1

    I think I started to understand VBA with you thank you so much Ms. Leila

  • @aricosman5354
    @aricosman5354 Před 3 lety +4

    GOD bless you Mrs Leila, Thanks a lot for your tutorials

  • @mobr.
    @mobr. Před 5 lety +4

    Clear, concise, and informative. Thank you.

  • @ckokse
    @ckokse Před 6 lety +4

    Thursday is my favorite day! I was already wating for your new video. This is great, will practice this as you instructed. I want to be prepared for when the VBA course finally comes out.

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      Mine too! Great. Practice is always good :))

  • @ca.lakshminarayanreddyjamb9087

    I like the way you explain. Really awesome!!! Thankyou.

  • @AamirSaeedTajalli
    @AamirSaeedTajalli Před 5 lety +1

    Lady Leila, I LOVE YOU for making this wonderful tutorial. Excellent TEACHER.. knowing the art of MAKING UNDERSTAND.
    Thanks a lot.

    • @LeilaGharani
      @LeilaGharani  Před 5 lety +1

      I'm very happy to hear this Aamir! Glad you like the videos.

    • @AamirSaeedTajalli
      @AamirSaeedTajalli Před 5 lety

      @@LeilaGharani i started watching your tutorials 3 days back and the more i am diving in, the more i am learning "FAST" and more i am liking your WAY of teaching. Full of confidence, command, knowledge and patience. GREAT WORK and inspiring achievements. Getting convinced to join your online tutorials paid version. I hope they will be even better.

  • @scorpio19771111
    @scorpio19771111 Před 2 lety

    Excellent video. You are great instructor, and the video is top-notch in clarity.

  • @lawrenceward2366
    @lawrenceward2366 Před 5 lety +1

    New to VBA. Most useful video I have seen. Thank you.

    • @LeilaGharani
      @LeilaGharani  Před 5 lety

      I'm very happy to hear that Lawrence. Glad you like the video.

  • @sasavienne
    @sasavienne Před 5 lety +4

    Cells.Columns.Autofit is lovely.
    Leila gets 🌟 🌟 🌟 🌟 🌟

  • @mariarib6504
    @mariarib6504 Před rokem

    omg. I'm not getting much sleep. I keep learning more from you and instead of fixing the basic stuff I have written, I am thinking of other things I can do! Thank you :-)

  • @MyChannel706
    @MyChannel706 Před měsícem

    Excellent video and narration! Thank you!

  • @konqueror07
    @konqueror07 Před 4 lety +1

    Awesome video. I think this should be the first video to watch for any one beginning to learn macros like me. I've spent hours trying to figure out how to refer cells in different scenarios.
    Can you also mention how to refer to variable ranges? Eg Range from A1 to Ai where "i" is a result of another formula or loop counter etc.
    Thanks for making a video on this topic though.

  • @SugarKane9547
    @SugarKane9547 Před 16 dny

    Thanks Leila,
    You just cleared up a lot of confusion I had about vba range referencing. I am very grateful......and YES, I like what I see but someone already subscribed before me! :)

  • @excelisfun
    @excelisfun Před 6 lety +10

    Awesome VBA Referencing video!!!! Quote Happy Fun : )

    • @antrikshsharma6990
      @antrikshsharma6990 Před 6 lety

      ExcelIsFun You should learn VBA as well😁

    • @excelisfun
      @excelisfun Před 6 lety +1

      Yes but where could I find a good class!?!?! ; )

    • @LeilaGharani
      @LeilaGharani  Před 6 lety +1

      Thanks Mike - yes...... not easy to find a good class ;))
      In the past week I've been locked up working on finalizing the course. I haven't had a chance to watch your videos, but I've added them all to my list. Have some catching up to do once I get out of here...

    • @antrikshsharma6990
      @antrikshsharma6990 Před 6 lety

      ExcelIsFun Try Wise Owl on youtube👍🏻

    • @excelisfun
      @excelisfun Před 6 lety +2

      Thank you for reaching out to me!!! But I am sorry, antiksh... I was making a joke... I already know about Wise Owl. I feature the Wise Owl channel and Leila's channel at the excelisfun Channel home page : ) I was making a joke that I should take Leila's class. But really it is no joke - she is so amazing at teaching and marketing and making videos : ) Go Amazing Online Excel Team, including you antiksh!!!

  • @teachmeteachme9014
    @teachmeteachme9014 Před 3 lety

    You're creative, so I've decided to outdo you in this field. تحية لك من المغرب

  • @cobusoosthuizen5223
    @cobusoosthuizen5223 Před 6 lety +1

    Thanks Leila, nice preparation for the upcoming course

  • @sanjaykulkarni1800
    @sanjaykulkarni1800 Před 6 lety +2

    Excellent way of explaining.. Thanks.

  • @joem112
    @joem112 Před 6 lety

    Very good video. I liked the way you did the drag and drop with the named range...pretty cool way to do that.

  • @LuisGarcia-mn4jg
    @LuisGarcia-mn4jg Před 3 lety

    You explain concepts very well and it is easy to follow. Thanks

  • @djibysadji9634
    @djibysadji9634 Před 4 lety +1

    So clear Leila! Thank you!

  • @abdallah.kandiel
    @abdallah.kandiel Před 6 lety +2

    Thankd leila
    Back to our happy day
    Waiting for the end to learn about the course
    Good luck ur highness

    • @LeilaGharani
      @LeilaGharani  Před 6 lety +1

      You're welcome.
      It's happy Thursday :) Wish you a great rest of the day.

  • @davecks3042
    @davecks3042 Před 4 lety +3

    I did enroll in Udemy in Leila VBA course and I learned immensely. Thanks

  • @alwysrite
    @alwysrite Před 9 měsíci

    was looking for multiple range syntax and found it here after looking on various sites. Thank you

  • @lilanthawijerathne3085

    Hats off to Leila ! . I learns lot from your videos.

  • @pponcho8245
    @pponcho8245 Před rokem

    Thank you for teaching the basics!!!!

  • @abumalik97
    @abumalik97 Před 2 lety

    impressive teaching ability , right pace and right details . subscribed !.

  • @Mario112352
    @Mario112352 Před 2 lety

    Very nice presentation
    Look forward to your course

  • @rnunez047
    @rnunez047 Před 2 lety

    In Spanish-language there's not channel like this one. Great, you have a nice voice, even my native language is Spanish, i get all you explain. I just founded you. Congratulations "Desde américa Latina, Nicaragua. Saludos"

  • @joecampanini8154
    @joecampanini8154 Před 2 lety

    Outstanding presentation. Thank you.

  • @johnborg5419
    @johnborg5419 Před 6 lety +1

    Thanks Leila. Very Interesting. Some practice and will wait for the next one :)

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      You're welcome John. Agree - practice is always good :)

  • @MrWofty
    @MrWofty Před 4 lety

    Oh Wow, solved my problem in a few easy minutes, well explained.
    I wish my school teachers, College Tutors etc, were like this.
    Thanks for giving me some enjoyment with learning :)
    I used this in Excel VBA "A1", "A" & lRow,
    Where lRow was the last row number.
    Cheers :)

  • @helenasvensson6595
    @helenasvensson6595 Před 8 měsíci

    So well explained, as always!

  • @j.fabricioelias227
    @j.fabricioelias227 Před 4 měsíci

    Thank you! This video gave me an excellent explanation about cells and ranges referencing.

  • @anilpanda5840
    @anilpanda5840 Před 5 lety +2

    Thanks a lot, very clear!

  • @YogeshSharma-ui7xx
    @YogeshSharma-ui7xx Před 3 lety

    Leila you r awesome and nicely explains with smile and simple way. Thank u

  • @mehdihammadi6145
    @mehdihammadi6145 Před 6 lety +2

    I am one of those who believe that there is always something to learn. And this has just been verified once again. Although I have been writing VBA code for years, I have never used the shortcut "?" in the immediate window because I used to write the entire debug.print command. So thank you very much Leila for this

    • @LeilaGharani
      @LeilaGharani  Před 6 lety +1

      Hi Mehdi. I'm glad you found something new here. Actually I was also not aware of the "?" method for the longest time after I started to use VBA. It made me very happy when I discovered it :)

    • @mehdihammadi6145
      @mehdihammadi6145 Před 6 lety +1

      Hi Leila, for the history this is an old (legacy) command coming from old versions of Basic. If my memory is good I used it with gwbasic for more then 25 years ago :)

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      Thanks for the info :)

  • @arielponce8586
    @arielponce8586 Před 3 lety

    You are an awesome teacher.

  • @irfanmansoori3060
    @irfanmansoori3060 Před 3 lety

    Unbeatable knowledge Leila.. thanks..

  • @umeshthadhani6388
    @umeshthadhani6388 Před 4 lety +1

    So Clear Explanation....!!! Makes understanding simple.! :) thank you So Much !! :)

  • @abdullahalklbani7454
    @abdullahalklbani7454 Před 2 lety

    Amazing 👏 that was full comparhansive explanation 👏
    I appreciate that efforts from your side
    This is was very helpful

  • @andydidyouhear
    @andydidyouhear Před 2 lety

    Great lecture, easy to follow.

  • @thirdfabe167
    @thirdfabe167 Před 5 lety +1

    really awesome,,i acquired a lot of knowledge in your video.

  • @SanjayKumar-yx6gc
    @SanjayKumar-yx6gc Před 6 lety

    Very useful lecturer Leila , Thank you so much.

  • @sasavienne
    @sasavienne Před 5 lety +1

    Brilliant. I like your videos Leila. Thanks a million.

  • @jokkiossaka3306
    @jokkiossaka3306 Před 5 lety

    Thank You Leila for your time and cool video !

    • @LeilaGharani
      @LeilaGharani  Před 5 lety

      My pleasure Jossi. Glad you like the video.

  • @ringsfieldvillagehallvilla7970

    This is fantastic. I will be taking the course at some point in the future.

  • @MrYegneswaran
    @MrYegneswaran Před 5 lety

    Very much insightful.. No need to refer to any other material as far as Range object though VBA..👍👍👍

  • @sindhusudhakaran1731
    @sindhusudhakaran1731 Před 3 lety

    so well explained. Thank you

  • @1gopalakrishnarao
    @1gopalakrishnarao Před 6 lety +1

    Thanks a lot Madam, very inspiring, illuminating, impressive, inquisitive & revealing, . Explanation is superb, very articulate. On behalf of all my Excel learner friends A BIG SALUTE TO MY BELOVED BEAUTIFUL TEACHER.

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      Thank you very much Gopala for the kind words and for your support. I am glad you're enjoying the VBA series so far :)

  • @sarasamin
    @sarasamin Před 5 lety +1

    Superb! Excellent!Thank YOU!

  • @alanliu1313
    @alanliu1313 Před 5 lety

    Very clear and useful!

  • @SolomonKinyanjui_sk
    @SolomonKinyanjui_sk Před 6 lety

    Hello Leila the lesson to day was very clear. Keep it up.

  • @annpurnakumari7218
    @annpurnakumari7218 Před 5 lety +1

    Really awesome. Thanks.

  • @cekhattaq
    @cekhattaq Před 3 lety

    Explanation is in very nice & systemic way, Thanks

  • @ah244895
    @ah244895 Před 4 lety +1

    Very clear, understandable. Great way to learn Excel m

  • @stevennye2441
    @stevennye2441 Před 3 lety

    excellent review!

  • @shoaibahmedsagar
    @shoaibahmedsagar Před 6 lety +1

    Thanks a lot Leila.

  • @marioalfredooviedo
    @marioalfredooviedo Před 4 lety

    buenos principios excel, tienes un gran poder de enseñar, hay personas que creen que solo se debe enseñar lo mas astral, pero los principios de excel son excelentes, te felicito

    • @LeilaGharani
      @LeilaGharani  Před 4 lety

      Thank you Mario. Glad you like the video.

  • @sarwansingh9423
    @sarwansingh9423 Před 4 lety

    This was very helpful

  • @nour-eddineoumakhlouf5296

    Great job, Leila!

  • @maryspurplelife2024
    @maryspurplelife2024 Před 5 lety

    Useful video, Thanks

  • @walek2001
    @walek2001 Před 5 lety +2

    thank you!

  • @21121990jay
    @21121990jay Před 4 lety +2

    Hi @Leila , how would you select two ranges and select them together ?
    E.g. Header should be fixed Range (First Range) and second range would be from active cell range.

  • @user-nm4ul6gr6o
    @user-nm4ul6gr6o Před 4 lety

    Thank You So Mutch.

  • @mohieddinedadi317
    @mohieddinedadi317 Před 3 lety

    thank you ; its useful

  • @aliz3700
    @aliz3700 Před 2 lety

    بهترین استادی👏👏👏

  • @steamsteam6607
    @steamsteam6607 Před 4 lety +2

    Such a smart, beautiful woman. Iran makes great things. Thank you for these videos.

  • @VRGuy286
    @VRGuy286 Před 3 lety

    Your videos are very informative. How do I reference entire rows as variables? For example if I am using them in a For/Next loop, instead of typing Rows("9:9").select? I can't figure out how to put a variable J in place of the 9's. Thank you.

  • @Vicky-bl9pr
    @Vicky-bl9pr Před 3 lety

    You are the best😊😊👌👌👌

  • @panagiotistheodorou4959

    Dear Leila, many thanks for your clear and advanced lessons taken here. Could you please let me know how can I write selective data records to a .txt file on disk and the ability to read a requested record from the .txt file on the disk back to excel with VBA.
    Thank you dear.

  • @mohitdhanwani5540
    @mohitdhanwani5540 Před 6 lety

    Thanks for the video ma'am.

  • @yoryopower2908
    @yoryopower2908 Před 3 lety +1

    Thank you.

  • @isa.rahban2132
    @isa.rahban2132 Před 3 lety

    thank you very much

  • @shameemnassiree2780
    @shameemnassiree2780 Před 6 lety

    Thanks ma'am 😊 your videos are quite helpful

    • @LeilaGharani
      @LeilaGharani  Před 6 lety +1

      You're welcome Sami. Glad to hear that :)

    • @shameemnassiree2780
      @shameemnassiree2780 Před 6 lety

      Leila Gharani Ma'am do u have videos on data validation, concatenation ?

  • @cananpasa5623
    @cananpasa5623 Před 3 lety

    Thanks a lot💕💕💕💕💕

  • @AliHasan-lr4xj
    @AliHasan-lr4xj Před 5 lety +1

    Very informative , but I have a request if you can show us how to merge cells than contains same value with option for Excel user to select the cells range as an input on dailog box
    Thanks

  • @abhilashc2965
    @abhilashc2965 Před 4 lety

    You are Divine. Demi God of Excel

  • @khalidalisubhanallah2947

    Bundle of Thanks Mam Nice Video

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      You're very welcome Khalid. Thank you for your support.

  • @robertakwasiadjei8223
    @robertakwasiadjei8223 Před 6 lety +1

    Thanks Leila for such a wonderful video. However, when is the course coming on?

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      You're welcome Robert --- should be live next week :)

  • @BOWENSblog
    @BOWENSblog Před 3 lety

    This is a good hobby

  • @petropasternak7087
    @petropasternak7087 Před 4 lety

    Hi Leila ,is it possible to use name reference and offset function to hide / unhide rows?
    Thank you very much

  • @jorge56149
    @jorge56149 Před 4 lety

    Thanks!

  • @cuneytozkurt4867
    @cuneytozkurt4867 Před 3 lety +1

    hi, your video is really great!
    I want to write a text every open sheets and for example there are 100 tabs open and I want to every A1 cells... Is there any way for this? thank you.

  • @donserpico8244
    @donserpico8244 Před rokem +2

    Hey Leila, thanks for your videos. I need to loop through a range (one column) and 1) check if the cell contains a specific text/string and 2) if true, write the text in a new cell (same row). Which of your tutorials do you recommend to watch? Also, I didn't find the next video/lecture you mentioned at the end of this one. thank you in advance

    • @souzamotasacul
      @souzamotasacul Před rokem +1

      Tomorrow, if I remember, I’ll write the code here for you 🤜🏼🤛🏼

  • @Galileo2pi
    @Galileo2pi Před 3 lety

    She is the best

  • @nancyd.5990
    @nancyd.5990 Před 5 lety +2

    U r the best

  • @shwan_ibrahim
    @shwan_ibrahim Před 2 lety

    thanl you so much

  • @satishpatel6530
    @satishpatel6530 Před 4 lety

    Nice video

  • @moisestatis5418
    @moisestatis5418 Před 10 měsíci

    I like how you teach. In fact, I'm enrolled in your Power Query Course. I'd assumed that you also have a Excel VBA course right? I'd like to learn macros.

  • @emisarangae125
    @emisarangae125 Před 4 lety

    Hello Leila, thank you so much for all your video tutorial, they are all so useful for people like me. I started a new job and will like to automate one of the reports in excel using VBA. I know what I want it to do but can't seem to figure out how to run the VBA to do it. Is it ok to contact you for help? Please help me!

  • @Youtubers789
    @Youtubers789 Před 5 lety

    Luv video. How do i use vba to delete a named range/ranges in a worksheet using vba code?

  • @fareedbadar8793
    @fareedbadar8793 Před 6 lety +1

    Thank you, for sharing useful information.
    Please can you advise how you open excel and vbe at the same time?

    • @LeilaGharani
      @LeilaGharani  Před 6 lety

      I snap the VBE window in place. You can use the shortcut key window and then right arrow. Or you can drag the VBE window with your mouse and then drag it to the right hand side until it snaps in.

    • @fareedbadar8793
      @fareedbadar8793 Před 6 lety

      I will try
      Thank you

  • @stockmarathihelpt8840
    @stockmarathihelpt8840 Před 5 lety

    Hello from India...I have query
    I want to paste a column from sheet 1 after every update in sheet 2 (but in different columns like Ist update in A column , second should be B ....like wise

  • @kaaa3485
    @kaaa3485 Před 4 lety

    Thank Leila for the video. I need your help. in excel, I have a button to clear cells when I click on it named "Clear", and I have another macro named "Fill cell" to fill cells with "OMIT" if the we select certain option from another data validation list; this last macro named "Fill Cell" will run after sub routine of change.
    My problem is when I click clear, it will will run also the macro that "fill cells". How can make not only run clear without executing the other macro "Fill Cell". Thanks in advance.