Excel VBA Macro: Pull Specific Columns from Another Workbook (Based on Header Values) Dynamically

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ธ.ค. 2024

ความคิดเห็น • 91

  • @amalhafiane7937
    @amalhafiane7937 2 ปีที่แล้ว +1

    Thank you so much!! You literally saved my internship

  • @timtom2150
    @timtom2150 ปีที่แล้ว

    The most helpful vba tutorial I've ever watched! Thank you so much!
    I had to modify a few lines since activating the source sheet didn't work for me, the row_count and col_count gave me values based on the worksheet I was importing the data to. So all the places that assumed using the active sheet, i added "ws_source." in front of like this:
    csv_path = "C:\Users\my_username\Documents\vba\source_data.csv"
    Set wb_source = Workbooks.Open(Filename:=csv_path)
    Set ws_source = wb_source.ActiveSheet
    Debug.Print "csv_path =" & csv_path
    row_count = WorksheetFunction.CountA(ws_source.Range("A1", ws_source.Range("A1").End(xlDown)))
    col_count = WorksheetFunction.CountA(ws_source.Range("A1", ws_source.Range("A1").End(xlToRight)))
    Debug.Print "row_count = " & row_count
    Debug.Print "col_count = " & col_count

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      Niiiice!! Glad it was helpful and that you got it working on your end!!

    • @timtom2150
      @timtom2150 ปีที่แล้ว

      @@greggowaffles Working really well thanks! I was running into an overflow issue however from the rows and columns being declared as Int rather than Long. Now all is good again

  • @umamakeshvasanth5786
    @umamakeshvasanth5786 ปีที่แล้ว +1

    Thank you man. Is there a way to pull columns from multiple sheets than just 1

  • @RameshAllur-f8w
    @RameshAllur-f8w 9 หลายเดือนก่อน

    This code is really great and simple Greg thanks

    • @greggowaffles
      @greggowaffles  7 หลายเดือนก่อน

      Glad you like it!

  • @siddharthmudaliar8720
    @siddharthmudaliar8720 ปีที่แล้ว +1

    I really cannot thank you much for a brilliant tutorial there. I was trying to work on a piece and was just not able to wrap my head around it. This video solved everything and the code looks so decent and clean.
    Fantastic job there mate.
    *Subscribed the channel 🎉🎉
    Keep up the good work

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      Thank you so much for the feedback! I’ll keep doing my best!!

  • @alexrosen8762
    @alexrosen8762 2 ปีที่แล้ว

    A very useful tutorial explained in an excellent way

  • @naomifagan2885
    @naomifagan2885 2 ปีที่แล้ว +6

    How do you pull columns in across multiple workbooks ??

  • @judithvalentine8931
    @judithvalentine8931 2 ปีที่แล้ว +1

    Hi Greg, Thank you very much for your videos, it's really helping me.

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว

      So glad to hear that! I’ll start making more soon!! Thanks for the motivation

  • @namith89
    @namith89 ปีที่แล้ว +1

    Hey Greg.. can you help with code for multiple worksheet.

  • @andrewliu309
    @andrewliu309 ปีที่แล้ว +1

    Hi Greg. This is very helpful. I'm creating this macro for other users to use so I've inserted a 2nd tab with comments and a macro button. Once I added a new tab, the macro does not work and the debug is highlighting the 'ws.Cells(1, 1).Select' line which I'm assuming could be because this works if there was only one tab in the workbook. How could I rewrite this if there was more than one tab?

  • @maxwurgler
    @maxwurgler ปีที่แล้ว

    Hi Greg, this is fantastic, thank you very much this is a great help and very well explained

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      Glad it helped and appreciate the feedback!!

  • @justinsingh6498
    @justinsingh6498 ปีที่แล้ว +1

    Hello Greg, I cannot thank you enough for this incredible tutorial ! You crushed it.
    The question I have after watching, and following along, is what needs to happen if you header row is not starting at A1 in the data workbook? "Thisworkbook" header is located at A1 but "Activeworkbook" is starting on row A5.

    • @aparnasundaresan7441
      @aparnasundaresan7441 8 หลายเดือนก่อน

      Hi Greg, will be helpful if you could give a solution for this.

  • @connorloze5418
    @connorloze5418 ปีที่แล้ว

    Hey Greg - this has been super helpful. One question I have is do you know a way to set criteria where the data I am pulling into the new workbook matches a specific date?

  • @pankajpathania5698
    @pankajpathania5698 ปีที่แล้ว

    Thanks for this.
    How to add to the first available row in the same code, if you can please reply.
    Thanks

  • @mostainbillah
    @mostainbillah 2 หลายเดือนก่อน

    Thanks For the tutorial , So i have need a code for the Active workbook specific range value Search from master book and copy . Paste Will Active Workbook .last Row . Need Some modify the code , please Help for the code ,Thanks

  • @ashercrush8953
    @ashercrush8953 2 ปีที่แล้ว

    hi Greg tks so much for the sharing ! btw how can i workout if i want to copy multiple sheets with selected column to a same destination sheet?

  • @hendrixchola5610
    @hendrixchola5610 4 หลายเดือนก่อน

    Thanks for the video.the challenge I have is that the macro is not copying and pasting the last four records. Please help

  • @mowgli536
    @mowgli536 2 ปีที่แล้ว +1

    Hi Greg. This is amazing! Thank you for sharing. I'm trying to do a reorder of 70+ columns within a table. And then potentially delete some columns that I do not need.
    Background: I have 1 master report that is used for multiple teams and some teams want it cut down to a smaller amount of columns. So what I'm hoping to do is create a bunch of macros (buttons) to allow the master report that has been pasted to "worksheet2'" to modify based on the button choice.
    How can I create a cleaner version of reordering columns within a table?
    ' Daily_Shortlist Macro
    '
    '
    Range("Customize_Shortlist[[#Headers],[Recruiter Name]]").Select
    Selection.Cut
    Range("Customize_Shortlist[[#All],[Super Sector]]").Select
    Selection.Insert Shift:=xlToRight
    Range("Customize_Shortlist[[#Headers],[Hiring Manager Name]]").Select
    Selection.Cut
    Range("Customize_Shortlist[[#All],[Super Sector]]").Select
    Selection.Insert Shift:=xlToRight
    Range("Customize_Shortlist[[#Headers],[Posting Status]]").Select
    Selection.Cut
    Range("Customize_Shortlist[[#All],[Super Sector]]").Select
    Selection.Insert Shift:=xlToRight
    Range("Customize_Shortlist[[#Headers],[Status]]").Select
    Selection.Cut
    Range("Customize_Shortlist[[#All],[Super Sector]]").Select
    Selection.Insert Shift:=xlToRight
    Range("Customize_Shortlist[[#Headers],[Senior Leader]]").Select
    Selection.ListObject.ListColumns(15).Delete
    Selection.ListObject.ListColumns(15).Delete
    Selection.ListObject.ListColumns(15).Delete
    Selection.ListObject.ListColumns(15).Delete
    Range("Customize_Shortlist[[#Headers],[Job Title(2)]]").Select
    Selection.Cut
    Range("Customize_Shortlist[[#All],[Super Sector]]").Select
    Selection.Insert Shift:=xlToRight
    End Sub

  • @Foskbou
    @Foskbou ปีที่แล้ว

    Hello Greg - this is the closest I’ve come to solving a problem! Thanks!
    I am looking to run this through a dynamic workbook I have been creating. What would advise on troubleshooting for no returns ?
    I am working with a large data set A1:AS1220 and various data types, copying this code did not work.
    Also need tips on how to copy filtered data.

  • @Exploretheexperiece
    @Exploretheexperiece 4 หลายเดือนก่อน

    What’s the software You are using Now?

  • @sharadpatel07
    @sharadpatel07 6 หลายเดือนก่อน

    Hi Greg its help me a lot but i have to paste data in other sheet & create multiple forms from master sheet, how can i do it ?

  • @CriticAL_EX
    @CriticAL_EX 2 ปีที่แล้ว

    works great ,but one problem , i have columns that have formulas and dates , and double or single variables , what should i change in this code so it does copy everything ?

  • @ritwiknautiyal2022
    @ritwiknautiyal2022 2 ปีที่แล้ว +1

    Hello Greg can you please modify the code as i want to paste the specific columns into a workbook but this workbook already has some data so i want to paste it below that. Mainly to the last available row of ws workbook. Can you please help me with that.

    • @Babs.K
      @Babs.K ปีที่แล้ว

      Did you ever figure this out?

  • @MF-cf8ez
    @MF-cf8ez ปีที่แล้ว

    Great tutorial! I m getting a Run-time 1004 error and I am not sure where I went wrong. Can you assist?

  • @tknaved
    @tknaved 2 ปีที่แล้ว

    very much thankful to u for this video...

  • @rodneyjones-dd8dr
    @rodneyjones-dd8dr ปีที่แล้ว

    I'm not a coder. I need help with my spreadsheet. I need to move data from a specific column to another sheet using a button. It's data from a pricing sheet to an invoice.

  • @tknaved
    @tknaved 2 ปีที่แล้ว

    excellent demonstration...

  • @totopanganiban7537
    @totopanganiban7537 ปีที่แล้ว

    how about adding another data from another sheet? thanks if you'll notice

  • @koushiknarendran2584
    @koushiknarendran2584 2 ปีที่แล้ว

    Hello, thanks for the video.
    I tried fetching data for 15 columns out of 120 columns but my destination sheet is blank. I don’t get any error message. Please help me out.

  • @zingfam7616
    @zingfam7616 ปีที่แล้ว

    Hi Greg, this is great, but when i tried, why did it only copy and paste to Coloum 1 only. where I have 6 headers and all matched. Any idea why ?

  • @jorge-3768
    @jorge-3768 2 ปีที่แล้ว

    Hi. Firstable thnx for the video its really hopefull. Then onlyn trouble ive got its that the columns i wanna import and match with the text of the header starts in A:3 i tried different stuff without sucess. Any idea please?

  • @Sk11257
    @Sk11257 ปีที่แล้ว

    its wonderfull, short vba code for excellent report generation

  • @irenesanjay
    @irenesanjay ปีที่แล้ว

    do u have the data file for this.

  • @jellybeanjellio8294
    @jellybeanjellio8294 3 ปีที่แล้ว

    Hi, I just found your channel. Y
    ou are amazing. You have helped me a lot so Thank You! I have a question. How do I write a macro code that refers to a list of delimiters in a lookup table in excel to remove any delimiter used in a column copied from a CSV file?

    • @greggowaffles
      @greggowaffles  3 ปีที่แล้ว +1

      Thank you! Glad to hear that! When you say “remove”, do you want to delete that cell, the contents of the cell, or the column itself?

  • @rautoramarautorama9324
    @rautoramarautorama9324 ปีที่แล้ว

    How do we do the same, using arrays?

  • @Jojosmith342
    @Jojosmith342 ปีที่แล้ว

    Hi Greg. I love all your tutorials as they are very practical and great code. There are some that you do not provide code and the screen hard to see even though I used to screenshot & magnify it I could not see either the colon, comma, colon lower L or 1. Very confusing when copying down your code. Videos with your code provided & clear screen help us so much and always received the most liked and I hope more will subscribe too. Your valuable time to make our lives easier, happier is always greatly appreciated. I always liked from the beginning class even though sometimes the program could not run smoothly because of the visibility. It took me sometimes to figure out ex: rg1 (it is number 1 but I write as L lower case) or criteria1 (number 1 but I wrote as letter L lower case) or the equal sign - I wrote as hyphen -. It would be nice if you could spell it out these little things or zoom the screen closer so that we can see better. Greatful for your hard work. thank you very much Greg!

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      Thanks! I’ll do better with that. And I’ll get the code added for all of my older videos

    • @Jojosmith342
      @Jojosmith342 ปีที่แล้ว

      @@greggowaffles You're genius coder and with strong passion to help people I believe you're successful. The number of subscribers will be increasing once you attach codes along with tutorials. 🙏

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      I really appreciate that!!

  • @katiebrehaut4315
    @katiebrehaut4315 หลายเดือนก่อน

    Please help me!! I want basically this however its not got a header. How do i create a macro in one workbook asking it to pull data from another workbook but by range.?
    I have four ranges c9:c130, GC9:GC130, GD9:GD130 and GG9:GG130
    Is this even possible?

  • @faizanmokashi5884
    @faizanmokashi5884 2 ปีที่แล้ว

    Hi, this one really helped but got some questions. Does this pull the data which is only text format? I tried the same codes but I m unable to pull the data from read only file

  • @RohitRajput01
    @RohitRajput01 2 ปีที่แล้ว

    Hi Thanks for the such h valuable video but i have try this but it's only pulled 15 row data not to the bottom why i don't know please help me out

  • @Yogeshkalra-z3v
    @Yogeshkalra-z3v 11 หลายเดือนก่อน

    Hi Greg code working but data no pasted

  • @Blueberryou
    @Blueberryou 2 ปีที่แล้ว +1

    mine can’t paste the values, it only closes the destination workbook 😅

  • @adamsreef
    @adamsreef 2 ปีที่แล้ว

    Hello greg. I need help with macro on how to auto filter, copy and save to new multiple workbooks a raw sheet and a summary sheet. So basically i have the first sheet as raw data and the second worksheet as with pivot table summary. Hope you can see this.

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว

      i hope this video helps!! th-cam.com/video/unUgUlEBvu4/w-d-xo.html i'll be making videos on using excel vba with pivot tables soon

  • @nextgenerationforchrist320
    @nextgenerationforchrist320 ปีที่แล้ว

    hi all, I was using this vba code in a project but as from yesterday it stops to copy in the destination excel.
    Can anyone help

  • @lenecaro8865
    @lenecaro8865 2 ปีที่แล้ว

    Great video! Using your example, how could I make it so it only pulled specific information? For example only want the data to pull if population is >= 150000

  • @MohAboAbdo
    @MohAboAbdo ปีที่แล้ว

    Thank you so much Sir

  • @blakehorner2949
    @blakehorner2949 2 ปีที่แล้ว

    Lots of good videos I've already seen and they've really helped me! So thank you!
    I'm currently investigating the ability of one excel document to pull information from another document. Two questions I have so far in this:
    1. Is it possible to make the file path adaptable? Where the document name can be changed but the column locations and everything are in the same location in every version of the document?
    2. Does all of this work whether you are in a normal file explorer or Microsoft Teams?
    I apologize, I've been working in Excel VBA for about 6 months now, but I have so much more to go, so I imagine this will not be the last time you will see me in your comments haha. I have managed to do a number of things with what I've learned, including changing a duplicate detection and deletion code to what I needed it to do, but I can't say for sure if it is the most efficient method possible.
    Thanks!

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว

      thanks for watching!!
      1. yeah, definitely. you can use wildcards and all that
      2. not exactly sure. i'll have to look into that
      apologies for the late reply btw! 😅

  • @AmitKumar-ng1od
    @AmitKumar-ng1od 2 ปีที่แล้ว

    Awesome Video,. Would be great help if we will be able to do the same thing from multiple workbooks.

  • @nagashreepradeepa
    @nagashreepradeepa 2 ปีที่แล้ว

    Hello, thanks for sharing this it is amazing..... I have tried this it work very well.... I have one question on this can we extract data from multiple files at one shot ...

  • @franklin07180
    @franklin07180 11 หลายเดือนก่อน

    Hi, bro.... i'm really appreciated for this job. i tried to do it and followed all your path but it still not run yet. it shows run time erro '438' Object doesn't support this property or method. please help me out to fix this error. i use excel 2010. thanks in advance.

  • @hekittyta9088
    @hekittyta9088 2 ปีที่แล้ว

    Hi greg, this is great, what if I'm pulling the data from the same workbook but in a different sheet

    • @wzclips4838
      @wzclips4838 2 ปีที่แล้ว

      Me too, same taks

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว

      hope this helps! th-cam.com/video/FxJpUajNOVs/w-d-xo.html

  • @nani21n58
    @nani21n58 ปีที่แล้ว

    greatwork buddy

  • @SantoshSoni-ly2sq
    @SantoshSoni-ly2sq 2 ปีที่แล้ว

    Amazing, Very Good Stuff... Can you also add a column and put the sheet name there.
    How to get data into one sheet if other workbook has multiple sheet (By country) with same header and column ?

  • @gayathrikannan5314
    @gayathrikannan5314 3 หลายเดือนก่อน

    I have a workbook with 800 column...code is opening the workbook but not copying to other

  • @rajsatarkar3605
    @rajsatarkar3605 2 ปีที่แล้ว

    Data header starts from 5th row what to do ???? Please help

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว

      row_count = WorksheetFunction.CountA(Range("A5", Range("A5").End(xlDown))) + 4

  • @keithrussellroldan7155
    @keithrussellroldan7155 2 ปีที่แล้ว

    This is a very nice share to us. I would like to add what if the header name is different from another worksheet/workbook (e.g. Population and Population (in K) )

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว +1

      You could use an if statement that uses the string “Population (in K)” instead of the cell

    • @keithrussellroldan7155
      @keithrussellroldan7155 2 ปีที่แล้ว

      @@greggowaffles Thanks for the reply. Will try to sort like that.

    • @greggowaffles
      @greggowaffles  2 ปีที่แล้ว +1

      No prob!

  • @Babar.Riaz1
    @Babar.Riaz1 ปีที่แล้ว

    Today after asking chatgpt this question again and again couldnt find the solution. Thats what i wanted.. Will test tomorrow

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      Happy to help!

    • @Babar.Riaz1
      @Babar.Riaz1 ปีที่แล้ว

      @@greggowaffles great it worked for me.. PS for all please note no header should be blank otherwise data wont be pulled, recommendation to author, to use in a title pull data from excel based on header values

    • @greggowaffles
      @greggowaffles  ปีที่แล้ว

      Thanks! I will make that update in the title

  • @dhavalahir6028
    @dhavalahir6028 2 ปีที่แล้ว

    application defined or object defined error on below lines
    ActiveSheet.Range(Cells(1, j), Cells(row_count, j)).Copy
    ws.Cells(1, i).PasteSpecial xlPasteValues

    • @charmisawla723
      @charmisawla723 2 ปีที่แล้ว

      Hi I am having the same error , did you get the way out?

  • @snehalpanchal4565
    @snehalpanchal4565 2 ปีที่แล้ว

    Awesome!!!! Point Blank... Bulls Eye... :)

  • @dhavalahir6028
    @dhavalahir6028 2 ปีที่แล้ว

    if possible kindly update greg