VBA to BROWSE & COPY Data from SELECTED File in Excel

Поделиться
HTML-код
  • Опубликовано: 3 окт 2024
  • Join 400,000+ professionals in our courses here 👉 link.xelplus.c...
    Use this simple Excel VBA macro to allow the user to browse for the file they need to import or copy the data from. They will get Excel's open File Dialog Box and they can browse and select the workbook to copy the data from. We use VBA GetOpenFilename method to Open the workbook selected in the background, copy the data and then close the workbook. The user will not even realize the other workbook was opened in the background.
    ⬇️ DOWNLOAD the workbook here: pages.xelplus....
    I will also show you how to avoid getting the message "method getopenfilename of '_application' failed". This is a common error when using the application.getopenfilename method and it can easily be avoided by declaring the correct variable type.
    👩‍💻 What You'll Learn:
    User Flexibility with GetOpenFileName: Understand how to allow users to select files via Excel's Open dialog box.
    Efficient File Handling in VBA: Learn to open, import, and manipulate data from selected files without hardcoding paths.
    Practical Example: Follow a step-by-step guide to open a file, copy a range, and paste it into a designated area in your workbook.
    Multi-Selection Feature: Discover how to handle multiple file selections for bulk data processing.
    🔥 Key Takeaways:
    Customizable File Paths: Free yourself from fixed file paths in VBA code or Excel cells.
    Simple Yet Powerful: Leverage the simplicity of the method for complex file handling tasks.
    Error Handling: Understand how to manage user cancellations and incorrect file selections.
    You can expand on this Excel macro to copy data from multiple ranges or multiple sheets or create dynamic ranges.
    Check out the FULL VBA Playlist: • Excel VBA & Macros Tut...
    ★ My Online Excel Courses ► www.xelplus.co...
    ➡️ Join this channel to get access to perks: / @leilagharani
    👕☕ Get the Official XelPlus MERCH: xelplus.creato...
    🎓 Not sure which of my Excel courses fits best for you? Take the quiz: www.xelplus.co...
    🎥 RESOURCES I recommend: www.xelplus.co...
    🚩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

Комментарии • 361

  • @LeilaGharani
    @LeilaGharani  8 месяцев назад +1

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

  • @ronvds4713
    @ronvds4713 5 лет назад +15

    Most people I deal with look at spreadsheets as a glorified calculator and are amazed at what I do for them. And then you come along and I am amazed.

    • @LeilaGharani
      @LeilaGharani  5 лет назад +6

      I'm glad I can still surprise you :)

  • @merbouni
    @merbouni 5 лет назад +1

    Well, in less than a year, you've become the number one as reference ... Everything is useful in your RUclips channel..😍

    • @LeilaGharani
      @LeilaGharani  5 лет назад

      Thank you, that makes me very happy :)

  • @djdisasterjames
    @djdisasterjames 4 года назад +7

    These lessons are so awesome, you really dive into every little detail and explain it so clearly :) Dim as String --> False = "False". Dim as Variant --> False = False :D I was baffled by that once, no doubt others also benefited from this!

    • @LeilaGharani
      @LeilaGharani  4 года назад +3

      I'm glad the tutorials are helpful for you James.

  • @shabbirkanchwala-abwaab6263
    @shabbirkanchwala-abwaab6263 5 лет назад +7

    Very useful hints
    B4 I never thought that such can be done in excel
    I always gain a lots of practical knowledge from your Vdo
    Simply U R Gr8!!!

  • @andyoverington712
    @andyoverington712 3 года назад

    Thank you. Finally someone who explains this stuff very well?

  • @MrKallemyran
    @MrKallemyran 5 лет назад +2

    This is something I'll actually use so thank you. And also You strike me as very pedagogical so I'll have a look-see if your courses are something i can take parallel to my work.. Fascinated by excels power. Mostly becaus it lets me "program" some simple things without the need to upgrade my IT security clearance in the organisation. As long as I'm within excel boarders. I'm allowed to build "smartnes" 💡

    • @LeilaGharani
      @LeilaGharani  5 лет назад +2

      I know exactly what you mean Thomas. Been in the corporate world myself for quite a while trying to navigate around the IT guidelines :)

    • @MrKallemyran
      @MrKallemyran 5 лет назад

      @@LeilaGharani ha ha Don't say it so loud ;) anyway... I have enrolled.. Now I have to find some time ⏳

  • @Thurmanatr16
    @Thurmanatr16 5 лет назад +4

    Never a dull video! 🙂Thank you for sharing your expertise with Analysts across the Corporate world. 😃

    • @LeilaGharani
      @LeilaGharani  5 лет назад +2

      I'm glad if my videos are helpful in the corporate world :)

  • @lephterisp
    @lephterisp 5 лет назад

    A whole new(amazing) world hidden behide Excel .Learning VBA is the next target for me.Thanks again for all you give to us .

  • @Matt-zp9jg
    @Matt-zp9jg 3 года назад +13

    For those wanting their copied range to be a bit more dynamic use this.
    OpenBook.Sheets(1).Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    The only problem with this is it stops if there are any empty rows. So make sure to check your data!
    LastRow = Sheets(1).Cells(Sheets(1).Rows.Count, StartCell.Column).End(xlUp).Row
    LastColumn = Sheets(1).Cells(StartCell.Row, Sheets(1).Columns.Count).End(xlToLeft).Column
    Sheets(1).Range(StartCell, Sheets(1).Cells(LastRow, LastColumn)).Copy
    This code on the other hand will work and count data even if there any empty rows between data. I'm still trying to incorporate this code into her macro to work so far no luck haha!

    • @danieljosiahquijano5659
      @danieljosiahquijano5659 Год назад

      ThisWorkbook.Worksheets("HW15").Range("A1").PasteSpecial xlPasteAll
      At this part, I am encountering error, that highlights this as yellow.
      Can somebody help?
      While my colleague uses the same code, but works fine.

    • @Matt-zp9jg
      @Matt-zp9jg Год назад

      @@danieljosiahquijano5659 Could be many things: possible your code has not selected anything to copy. Paste will fail if nothing copied. Your range is different than your paste area.
      Also better to use this: high lighting entire column a even Blanks.
      Dim rng As Range
      Set rng = Range("A2", Range("A" & Rows.count.End(xlup).Address)
      rng.Copy
      Range("B2").PasteSpecial xlPasteAll

    • @johnhayse7147
      @johnhayse7147 Год назад +1

      @@danieljosiahquijano5659 Did you figure it out? I'm have the same problem :/

    • @danieljosiahquijano5659
      @danieljosiahquijano5659 Год назад +1

      @@johnhayse7147 I did, when you are recording a macro, under "Store macro in", select dropdown "This Workbook". it is a very specific code.

    • @johnhayse7147
      @johnhayse7147 Год назад +1

      @@danieljosiahquijano5659 Thanks!

  • @mellowkoopa
    @mellowkoopa 5 лет назад

    This came up in my Google news feed, like sweet nectar of information magic'd down from the heavens to solve a problem I didn't know I had. Thank you so much for your very clear and concise tutorial. Subscribed.

    • @LeilaGharani
      @LeilaGharani  5 лет назад

      You're very welcome. I'm glad to have you here.

  • @matthewmusselwhite591
    @matthewmusselwhite591 Год назад

    You are truly amazing and a very gifted teacher. Thank you for all you do!!

  • @vishalpatil4102
    @vishalpatil4102 3 года назад

    Thank you for the valuable information, i have purchased all of your courses from udemy. They are so very helpful

  • @olibolivar7223
    @olibolivar7223 5 лет назад +1

    I really learn new things every time I watch your videos. Thanks a lot! :D

  • @ruteshrudra6320
    @ruteshrudra6320 4 дня назад

    Thanks for this video and it is really helpful but how to create data should select and copy data dynamic

  • @dhruvakerkar6956
    @dhruvakerkar6956 3 года назад

    Wow
    I was actually using "Path" option in excel all this long...this really help...Thanks

  • @craiggibson8547
    @craiggibson8547 5 лет назад +1

    I’m doing the VBA course at the 😆moment. Very impressive, well structured and well explained stuff. Great job Leila 👍

    • @LeilaGharani
      @LeilaGharani  5 лет назад

      That's great Craig. I'm glad you like the course. Many thanks for the feedback!

  • @Things-Recycleing
    @Things-Recycleing 5 лет назад

    Thanks for usual support in Excel every day learn new topic

  • @GrahamSchroder
    @GrahamSchroder 4 года назад

    Your channel is brilliant!
    I learn so much. Thanks!

  • @dkb1111
    @dkb1111 5 лет назад

    हर बार कुछ नया ,धन्यवाद लीला

  • @anomolyreport
    @anomolyreport 5 лет назад

    And here I thought openfiledialog and filesystem objects are the only ways to get file names..
    Thank you!!

  • @arere9948
    @arere9948 Год назад

    TYSM for such an informative instruction, help me a lot 🥰

  • @coffeecuppepsi
    @coffeecuppepsi 5 лет назад +43

    If someone doesn't like spreadsheets its just that they haven't seen this channel

    • @ckokse
      @ckokse 5 лет назад +1

      So true!

    • @wuphysics87
      @wuphysics87 5 лет назад +1

      Or because spreadsheets are the wrong tool for the job most of the time

    • @suresha2622
      @suresha2622 4 года назад

      I am trying to find a VBA code that will find a file utilizing where only the first six characters in the file name are always same and the file name ends with YYYY.MM.DD.xlsx.
      now my file is under 2020 folder and have to create seprate folder for each monts like Jan, Feb and Mar under 2020 folder, then in the each month file we have to change and create file on daily basis
      like this _ Y:\C & C FEES\Suresh\anbu 2020\04_Apr 2020\InvoicesDD.MM.YY(daily need to change the file date and monthly once change the month).

  • @gutobrasiliabrasil
    @gutobrasiliabrasil 3 года назад

    Great!!!
    It is exactly what I was looking for!!!
    You are the best!!!

  • @jmstampe
    @jmstampe 5 лет назад +5

    Between this and ADO....these are my two faves to impress the non-technical

  • @ExcelExciting
    @ExcelExciting 5 лет назад +2

    Great Video 👍🏻.. thanks for sharing

    • @LeilaGharani
      @LeilaGharani  5 лет назад +1

      Thanks for the lightning fast comment Faraz :)

  • @kurtauerbach5883
    @kurtauerbach5883 3 года назад

    Thanks this really helped me out. Clear and not boring!

  • @hadiasghari2266
    @hadiasghari2266 3 года назад

    u r my excel hero

  • @smohanv
    @smohanv 5 лет назад

    This is a kind of VBA idea i was searching for. Thanks. I have subscribed to this channel as well. Thanks a million.

    • @LeilaGharani
      @LeilaGharani  5 лет назад

      Glad to help. It's great to have you here.

  • @hddevani
    @hddevani 5 лет назад +1

    As always, excellent Top-Notch Pure explanation...

  • @prakharsrivastava7795
    @prakharsrivastava7795 2 года назад

    Thank you so much!! Extremely helpful video!!

  • @vengamanaidu996
    @vengamanaidu996 5 лет назад

    You are my teacher madam, i learned lot from you

  • @mhmdseadawy8228
    @mhmdseadawy8228 2 года назад

    Thanks for this useful lesson, you are the best 👏👏

  • @alexpspa60
    @alexpspa60 5 месяцев назад

    amazing!!! do you have a video on how to import multiple files?! 😊

  • @ראזיכיסראוי
    @ראזיכיסראוי Год назад

    BIG THANKS LAILA

  • @FPAmitKachalia
    @FPAmitKachalia 4 года назад

    Hi Leila. This video has really helped in one of my excel project of my process flow. I sincerely appreciate you for making this video. I would have loved to share my automation made out of this information, but, considering confidentialty, not possible. Thanks again for making and sharing. Will also go through your other videos.

  • @spunjbom
    @spunjbom 5 лет назад +1

    Awesome job, Leila! I can see myself using this in the future.

  • @sasavienne
    @sasavienne 5 лет назад

    Excellent.. Thank you very much for sharing your valuable knowledge with us Leila. 👍 👏 🌟

    • @LeilaGharani
      @LeilaGharani  5 лет назад +1

      You're very welcome. Glad you like it.

  • @michelacosta9886
    @michelacosta9886 Год назад

    Very good Leila!!! than
    ks for this video!!!

  • @arifhk007
    @arifhk007 5 лет назад

    I like your videos from other youtube videos...Coz your teaching style is very helpful and clear!
    Thank you, Mam!

  • @thomasfetter
    @thomasfetter Год назад

    you are just awesome

  • @wayneedmondson1065
    @wayneedmondson1065 3 года назад

    Hi Leila. Great tutorial! Thanks for sharing this :)) Thumbs up!!

  • @tha2irtalib343
    @tha2irtalib343 5 лет назад +1

    beautiful mind , and good teacher , thank you leila .

    • @craiggibson8547
      @craiggibson8547 5 лет назад

      @tha2ir Talib beautiful teacher, and good mind, thank you leila .

  • @Fatfingertunes
    @Fatfingertunes 2 года назад

    Thanks! Always very helpful!

  • @stephanie_ong
    @stephanie_ong 3 года назад

    Thanks! I was able to use your method perfectly :)

  • @spneerajmishra
    @spneerajmishra Год назад

    Great help thank you 😊

  • @FanJapanStudios
    @FanJapanStudios 5 лет назад +1

    Best 👏 Channel 👏 EVER!!! 👏

  • @jayeshjamtani924
    @jayeshjamtani924 5 лет назад

    Thank you #LeilaGharani #ExcelQueen for sharing this wonderful way to open files. I am a big fan of yours ( more than of Excel )

  • @augustodemelo915
    @augustodemelo915 3 года назад

    It is great!!!
    Thank you so much for this very valuable information.

  • @samirmohapatra8582
    @samirmohapatra8582 Год назад

    Very useful ❤. Thank you so much 😊

  • @ashrafgharsan553
    @ashrafgharsan553 4 года назад

    Very useful and practical. Thank you for the great material!

  • @sarfarajkureshi6569
    @sarfarajkureshi6569 5 лет назад

    Nice tutorial mam. God bless you

  • @m1cannas
    @m1cannas 2 года назад

    You rock the item. Super

  • @joecross5335
    @joecross5335 5 лет назад

    Helpful. I didn't know that method existed.

  • @rahulbakshi285
    @rahulbakshi285 5 лет назад

    Thanks Leila, I got your VBA videos.

    • @LeilaGharani
      @LeilaGharani  5 лет назад +1

      That's great Rahul. Thanks for your support.

  • @ramavtarsingh146
    @ramavtarsingh146 2 года назад

    Very useful thanks a lot, Keep it up.

  • @shrutiagarwal936
    @shrutiagarwal936 4 года назад +2

    Hi, i really like how easily and precisely you explain things. I have a query though, what should i do if i want to get data by opening a link which is a link to excel sheet and not from any worksheet which is saved in my PC.

  • @jeandaniel521
    @jeandaniel521 2 года назад

    Amazing, this saved me so much time :)

  • @civilworks3591
    @civilworks3591 4 года назад +1

    hi, thank you for lots of tutorials you made. appreciate if you continue or added the program to paste on the last row please. TIA.

  • @abdallah.kandiel
    @abdallah.kandiel 5 лет назад

    Happy Thursday your highness
    This is not fair, you publish your jewels while me at work.😅
    I can't return to my firsts💪
    Anyways
    You are the one
    I'll brb after watching
    Thanks in advance ♥

    • @LeilaGharani
      @LeilaGharani  5 лет назад +1

      First or not I'm always happy to see your comments :)

  • @farizpatah4081
    @farizpatah4081 5 лет назад

    Finally got this macro.. Thanks a lot...

  • @Llb890
    @Llb890 5 лет назад

    this is the way to increase knowledge

  • @twgrisham
    @twgrisham 4 года назад +1

    Well done. Very easy to follow and understand. How would handle a dynamic range in OpenBook?

  • @youzaist
    @youzaist 4 года назад

    You are the best ever.... life saver oh my gosh

  • @yflow5337
    @yflow5337 2 года назад

    How a beautilul Women! And how helpful information!

  • @yulinliu850
    @yulinliu850 5 лет назад

    Great teaching of VBA. Thanks Leila!

    • @LeilaGharani
      @LeilaGharani  5 лет назад

      You're very welcome. Glad you like the tutorial.

  • @JG-fg1ye
    @JG-fg1ye 5 лет назад

    excel-lent as always, Leila is stunning 👍🏻

  • @ฉันเรียนไปเรื่อย

    Thanks a lot. it is usefully for me

  • @Interphaseable
    @Interphaseable 3 года назад

    Wonderful video!

  • @venkatraghavanr5169
    @venkatraghavanr5169 3 года назад

    Good one...btw, how can someone dislike this video ?

  • @Khalnayak_sanju143
    @Khalnayak_sanju143 5 лет назад

    Wow thank you mam ,it's helping me on my work Thanks Once again

  • @mc24bk
    @mc24bk Год назад

    Great video, very easy to understand. How to copy the entire column A & B without setting a range number?

  • @francoismarsau6412
    @francoismarsau6412 2 года назад

    Great videos as always. I have signed up for some courses of yours to learm more. You are geat teacher. you mentioned that " and copy specific ranges and import them in our file will be shown later how to do". Can you give example of this or tell me lesson no in you course that explains this as I could not find it. Thank you once again for great courses and video content.

  • @nielskock3221
    @nielskock3221 5 лет назад

    absolutely awesome thanks. Actually just what I was looking for thanks!

  • @johnborg5419
    @johnborg5419 4 года назад

    Wish I could do that :) :) I am enrolling to your course for sure.

  • @robertakwasiadjei8223
    @robertakwasiadjei8223 5 лет назад

    Very much grateful Leila.

  • @MohAboAbdo
    @MohAboAbdo Год назад

    Thank you so much

  • @shaheershujaat2223
    @shaheershujaat2223 5 лет назад

    Wow Leila you are looking very nice beautiful and amazing video well done 😊😊❤️❤️👍👍

    • @LeilaGharani
      @LeilaGharani  5 лет назад +1

      Thank you, glad you like it :)

    • @shaheershujaat2223
      @shaheershujaat2223 5 лет назад

      My pleasure Leila yup a lot 😊😊❤️❤️👍👍

  • @buradagunta1
    @buradagunta1 3 года назад +2

    Hi, this is very helpful. would you explain considering the csv file instead xlsx file, copy data from sheet 1 of csv file opened and paste in the current workbook. Thank you

  • @esbi1124
    @esbi1124 4 года назад +1

    Really good!

  • @samehtalaat56
    @samehtalaat56 2 года назад

    Amazing! Really helpful :-)

  • @pedroantas3553
    @pedroantas3553 2 года назад

    Excelent. Thanks :)

  • @olibolivar7223
    @olibolivar7223 4 года назад

    Woah! Just what I needed. Thanks! :D

  • @jaypeehernandez4029
    @jaypeehernandez4029 4 года назад

    Amazing as always.

  • @samirawati1975
    @samirawati1975 Год назад

    Wouderful video madam, can you please give this file for practice in description

  • @chanchaldas6229
    @chanchaldas6229 4 года назад

    Thanks mam for this useful code।❤️❤️❤️

  • @barejam
    @barejam 4 года назад

    Excellent! Thank you :)

  • @yurd563
    @yurd563 5 лет назад

    Thanks for video!

  • @mohdkharish8169
    @mohdkharish8169 5 лет назад

    Thanks a lot.. Awesome.. for next can you update for select file with multiple file.. Thanks

  • @walelaiouattara4882
    @walelaiouattara4882 5 лет назад

    Thanks, nice and helpfull.

  • @excelaficionado
    @excelaficionado 5 лет назад

    Awesome video as always....

  • @vaishalikhedlekar3733
    @vaishalikhedlekar3733 3 года назад

    This is really great !! But would like to understand how can we apply filter on the selected file based on a certain criteria and copy only the filtered data on the macro workbook.

  • @LongTruong-kh4vi
    @LongTruong-kh4vi Год назад

    thanks so much

  • @r2r616
    @r2r616 3 года назад

    Love it, thanks. Simple and effective. Used it to automate my tax calculations for GME tendies ❤

  • @Ca7a1n
    @Ca7a1n 2 года назад +1

    Hi Leila and thank you very much for your useful videos!
    I have a problem with this code - it doesn`t work on MAC.
    Do you have a solution for this ?
    Thank you!
    Best regards!

  • @justinsincoise6693
    @justinsincoise6693 Год назад

    I work in a hotel as a night Auditor. Someone managed to do his job at a fraction of a time because of time. Been trying to find out how he could import the report from our opera cloud into our excel. In a form of a format. This video gives a good example but I still need help. 😮

  • @gamingstudio9949
    @gamingstudio9949 5 лет назад

    Very nice video

  • @chamindabasnayake4844
    @chamindabasnayake4844 5 лет назад

    Great! Thank you Leila!

  • @nevermind4780
    @nevermind4780 5 лет назад

    another creative ideas ☺👍👌

  • @rodrigodavalle5738
    @rodrigodavalle5738 5 лет назад +3

    This is great! Thank you so much. I would like to know how should I change the code in order to paste the range in the active cell?