VBA to BROWSE & COPY Data from SELECTED File in Excel

Поділитися
Вставка
  • Опубліковано 25 вер 2019
  • Join 400,000+ professionals in our courses here 👉 link.xelplus.com/yt-d-all-cou...
    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.com/vba-select-...
    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.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

КОМЕНТАРІ • 359

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

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

  • @ronvds4713
    @ronvds4713 4 роки тому +13

    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  4 роки тому +5

      I'm glad I can still surprise you :)

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

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

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

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

  • @djdisasterjames
    @djdisasterjames 4 роки тому +6

    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 4 роки тому +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!!!

  • @Thurmanatr16
    @Thurmanatr16 4 роки тому +4

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

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

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

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

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

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

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

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

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

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

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

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

    Best 👏 Channel 👏 EVER!!! 👏

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

    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  4 роки тому

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

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

    Woah! Just what I needed. Thanks! :D

  • @JG-fg1ye
    @JG-fg1ye 4 роки тому

    excel-lent as always, Leila is stunning 👍🏻

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

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

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

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

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

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

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

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

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

      Thank you, that makes me very happy :)

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

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

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

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

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

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

    Amazing as always.

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

    Thanks! Always very helpful!

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

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

    beautiful mind , and good teacher , thank you leila .

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

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

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

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

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

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

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

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

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

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

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

    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  4 роки тому

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

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

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

  • @thomasfetter
    @thomasfetter 10 місяців тому

    you are just awesome

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

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

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

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

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

      You're very welcome. Glad you like it.

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

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

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

  • @Things-Recycleing
    @Things-Recycleing 4 роки тому

    Thanks for usual support in Excel every day learn new topic

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

    You are my teacher madam, i learned lot from you

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

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

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

    Awesome video as always....

  • @arere9948
    @arere9948 10 місяців тому

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

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

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

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

    Very informative.
    Gonna try it later.

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

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

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

    Great help thank you 😊

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

    Excellent! Thank you :)

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

    Wonderful video!

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

    Thanks Leila, I got your VBA videos.

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

      That's great Rahul. Thanks for your support.

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

    Very useful ❤. Thank you so much 😊

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

    Just amazing!!

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

    Really good!

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

    Thanks for video!

  • @MrKallemyran
    @MrKallemyran 4 роки тому +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  4 роки тому +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 4 роки тому

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

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

    Nice tutorial mam. God bless you

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

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

    Very useful thanks a lot, Keep it up.

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

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

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

    Great! Thank you Leila!

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

    Great Video 👍🏻.. thanks for sharing

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

      Thanks for the lightning fast comment Faraz :)

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

    Thanks, nice and helpfull.

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

    Very much grateful Leila.

  • @user-zu5fe9yi2m
    @user-zu5fe9yi2m Рік тому

    BIG THANKS LAILA

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

    Amazing! Really helpful :-)

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

    great video!

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

    u r my excel hero

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

    You rock the item. Super

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

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

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

    Incredible, this is exactly what I was just searching for! So much thanks! :))>

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

    Helpful. I didn't know that method existed.

  • @jmstampe
    @jmstampe 4 роки тому +5

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

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

    another creative ideas ☺👍👌

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

    Thank you so much!!!!

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

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

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

    Amazing, this saved me so much time :)

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

    Awesome!

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

    nice job! thanks :)

  • @user-zh7km3ph7b
    @user-zh7km3ph7b 3 роки тому

    Thanks a lot. it is usefully for me

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

    Thank you so much for this video. How can I adopt this script for importing a complete csv file and pasting it in a specific cell?

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

    Thanks for your excel related content. I was wondering, can Google sheets open (and run) excel files containing macros (buttons, for instance)?

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

    Thank you so much

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

    Excelent. Thanks :)

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

    Very nice video

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

    Hello good night your video is very well explained, I just wanted to ask a question: How can I make a filter inside the files that opened and copy the data from the filter result?

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

    This is great!

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

    thanks very much

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

    Hi Leila, thanks for the great video's I generally watch all of them, I have a small problem, I get Excel files from different members of which I open and then import into my Excel data, the problem is they have a verity of extensions such .xls, .xlsx,.xlsm is there a way to be able to use with an open workbook, your comments would be much appreciated
    Regards..Don.

  • @LongTruong-kh4vi
    @LongTruong-kh4vi Рік тому

    thanks so much

  • @coffeecuppepsi
    @coffeecuppepsi 4 роки тому +43

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

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

      So true!

    • @wuphysics87
      @wuphysics87 4 роки тому +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).

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

    very interesting 😀

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

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

    Hi Leila! Thanks so much for this video. I followed this pretty much step by step, but I'm getting a 'subscript out of range' error. I'm looking at the documentation to understand this error in this context, but I'm not comprehending. Do you have resources or tips on how to debug this?

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

    Wonderful

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

    Thank you!

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

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

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

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

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

    Very nice

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

    Thaks you!!

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

    Dear Leila
    Thanks for useful videos.
    Please help me to find out how I can import file like jpg that start from cell for example left top corner of picture comes from cell A10.

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

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

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

    Fantastic video. Exactly what I need. After the user selects the file, is there a way for the user to select which data he/she would like to copy into cell A10?