+ Reply to Thread
Results 1 to 16 of 16

HELP - Extract column specific data

  1. #1
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Post HELP - Extract column specific data

    Hi

    I was hoping someone could give me some advice. I have attached an example of what I am trying to achieve.

    In sheet 1 I have a set of data. I am trying to extract specific columns from that set of data into a new sheet called "EXTRACT". It works as long as I want to extract data into column A of the "Extract" tab. However soon as I want to extract data into column B or C or any other column it does not.

    So for example if we look at the code below, if I change the first paste (Sheet1.Paste Destination:=Worksheets("EXTRACT").Cells(erow, 1)) to another column such as (Sheet1.Paste Destination:=Worksheets("EXTRACT").Cells(erow, 2)) it stops working.

    I am sure I am missing something simple so if someone could help me it would be appreciated!


    Sub Dump()

    Dim lastrow As Long, erow As Long
    lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

    For i = 2 To lastrow
    Sheet1.Cells(i, 1).Copy
    erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    Sheet1.Paste Destination:=Worksheets("EXTRACT").Cells(erow, 1)

    Sheet1.Cells(i, 3).Copy
    Sheet1.Paste Destination:=Worksheets("EXTRACT").Cells(erow, 9)

    Sheet1.Cells(i, 6).Copy
    Sheet1.Paste Destination:=Worksheets("EXTRACT").Cells(erow, 10)

    Next i
    Application.CutCopyMode = False
    Sheet2.Columns().AutoFit
    Range("A1").Select

    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    When you say not working... what is not working? because erow is used to know which line to paste data in on the Extract sheet, so you need to change the 1 in
    Please Login or Register  to view this content.
    to also match the column you are switching to in your code, or the code will keep pasting in the wrong row over and over.

    Also, please put code tags around your code when pasting. Highlight the part that is code, and hit the # icon
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Hi Arkadi


    Thank you very much for your help! Much appreciated!

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    No problem, did that fix it?

  5. #5
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Yeah - it worked great!

    Thanks for pointing it out, I was looking at the same code for ages!

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    Glad to help
    Please mark the thread as solved if you are satisfied (Thread Tools menu option at the top)

  7. #7
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Hi

    My previous issue is now fixed, but I now have another related problem. When I run the macro through a large set of data, it crashes my workbook.

    Therefore do you know of a way that I can modify the code that would help prevent this issue?

    I have attached a file with lots of data in which is representative of the amount of data I will have in my excel file. When you press the macro you will see the issue.

    Can you help please?
    Attached Files Attached Files

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    Not sure why it freezes, though your Dump module is not so efficient, too much work. Copying/pasting every time is way more work than just making the cell's value equal the source value, since you want variable columns (based on earlier request), I have kept my changes to a minimum, though you are best off copying the whole ranges in one shot I think. That said, using a loop I'd suggest this instead:

    Please Login or Register  to view this content.
    I turned off screenupdating during the copying, and also calculated erow once at the start, then just keep increasing by 1, thereby reducing the workload significantly.

  9. #9
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Hi

    That worked great!! Many thanks again!

  10. #10
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Hi

    Thanks for your help previously - the solution you gave has been working well.

    However I have tried to modify it slightly by only returning data that meets a certain criteria. However whilst it works it also brings back blank cells (where I presume the data that I do not want to be returned would have been).

    Do you know how I can copy only the data that I want (as therefore no blank spaces are copied over) please??

    Here is the modified code to what you helped me with below. I have also attached an example worksheet.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    I think the blanks are coming because you are putting erow = erow +1 outside the if statement, so whether it copies or not, it moves down one row the destination sheet. just put
    Please Login or Register  to view this content.
    BEFORE
    Please Login or Register  to view this content.
    Let me know if that works out if not we will dig deeper.

  12. #12
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Hi Arkadi

    Thanks for your response. It almost works but it does not extract all the data (it has got rid of the blank spaces).

    The example I have attached shows it extracts 733 rows of data although when I manually do a filter it shows there are 16765 "active" entries in column R.

    Any ideas...maybe I need to change something in the code?

    Thanks for your help - its appreciated!!
    Attached Files Attached Files

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    any chance some say "active" and some say "Active" ? Nevermind... lol I'll check myself and get back to you

  14. #14
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    hmm..I dont think so. I had a quick look over the list and I cannot see any differences in capitalization. If there are, I dont think there is enough to make up the difference between what is rally there and what is being extracted.

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: HELP - Extract column specific data

    Oh lol, your if statement should be using i and not erow in the row reference...
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    Also at the bottom I made a mistake in the original, not that it matters much but it should be
    Please Login or Register  to view this content.
    Last edited by Arkadi; 06-01-2015 at 02:21 PM.

  16. #16
    Registered User
    Join Date
    05-24-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    35

    Re: HELP - Extract column specific data

    Awesome!! Thanks again Arkadi! Works well - you are a champ!


    Much appreciated!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extract data in specific row/column?
    By hockeyadc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2013, 10:19 AM
  2. Extract specific column data from specific sheet from multiple files in a folder
    By piggyfox in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-31-2013, 11:51 AM
  3. Macro to extract data from multiple workbooks, specific sheet, specific cells
    By crissandraauree in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2012, 03:54 PM
  4. Replies: 1
    Last Post: 04-23-2012, 10:27 AM
  5. Replies: 1
    Last Post: 12-22-2011, 03:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1