+ Reply to Thread
Results 1 to 12 of 12

Macro to extract cell content and "rejig" columns

  1. #1
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Macro to extract cell content and "rejig" columns

    Hi folks,

    I have been tasked to process on a regular basis several large files (~200,000 lines) after spending all day yesterday to work on one only, I'm thinking there must be a way to do it via VBA. I was hoping someone could point me in the right direction as I've searched the web for answers and couldn't find anything

    Basically, the file lists in column A all the assets we own; in column B, the stock items that make these assets; in column C, the stock items that make these stock items in column B; in column D, the stock items that make these stock items in column C, etc until column F

    Unfortunately I can't change the way this data is extracted and need to change the layout for processing separately: what I need to achieve is a list over two columns only that basically say that if something was in column C, it needs to be brought back in column B against the same asset (in column A), if something was in column D, it needs to be brought back as well in column B against the same asset.

    Other than this massive rejig, I would need to exclude from column A all the numbers and subsequent letters that are after the third "-", and extract from columns B, C, D, E, and F only the first 9 characters.

    As I'm writing this I realized how confusing it is so I have attached an example which hopefully explains it.

    If it is not doable, then so be it and I'll stick to manual processing but geeeee it is an awful process!

    Thanks to anyone who will read this
    S
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract cell content and "rejig" columns

    Assuming the workbook has two sheets in it named BEFORE and AFTER, put the data as shown into the BEFORE sheet and run this macro:
    Please Login or Register  to view this content.
    I highlighted in red a line of code that is removing the duplicates, so each A:B set of values will be unique. Remove that if you want the dupes.
    Last edited by JBeaucaire; 09-15-2016 at 11:35 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Re: Macro to extract cell content and "rejig" columns

    holy moly that's impressive, like really impressive.

    I got a syntax error on the red duplicate line but would love to be able to use it. The only thing is that the same stock code could be against different assets so I would like to keep these, but delete when the same stock code is listed several times against the same asset.

    Finally, what would I change in the code if I wanted (for example) to have the output stock codes in column C rather than B?

    I can't thank you enough, you turned a 8-hour process into something that literally takes seconds.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract cell content and "rejig" columns

    Code in post #2 has been fixed and won't error now. The "Remove Duplicates" thing is removing duplicated rows of A:B combined, when an Asset and Stock Code appear together more than once. So I think it should stay in based on what you said.

    What happens to column B? You can just cut/paste the output to column C, but what is happening in column B instead?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract cell content and "rejig" columns

    Here's the version that outputs to A and C.
    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks. It is customary to give feedback to those that have helped you by clicking on the asterisk (Add Reputation) at the bottom of their post.

  6. #6
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Re: Macro to extract cell content and "rejig" columns

    Hi there,

    For the time being I'm using the macro that extracts in column B (C will be in a couple of weeks based on new data) but it seems something has gone wrong since your edit.

    I now get an "run time 1004 error" as well as no data in column B (the title "Stock Code" disappears) and the last digits still present in column A. Did something change significantly or am I doing this wrong?

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract cell content and "rejig" columns

    Here's the file I was testing on.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Re: Macro to extract cell content and "rejig" columns

    The fact that I had some fields populated in the "After" sheet obviously stuffed it up cause I did what you add and it worked so thank you very much Only problem is that it does not extract the letters after the second "-".

    One final question: if I wanted to look up a section of the first column (for example in AGITATOR-KW008-LST00N I look for the 008 knowing that it could be longer than 3 characters) in column A of a separate sheet and return the adjacent value in column B, would I be better of having a macro saying the following or finding a macro that does the search on its own:
    Please Login or Register  to view this content.
    Thanks again.
    S
    Last edited by SubwAy; 09-19-2016 at 01:18 AM.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract cell content and "rejig" columns

    Glad it's working. Not sure how to respond to that final question in context. Perhaps if I could see that need in your workbook demonstrated I could answer.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks. It is customary to give feedback to those that have helped you by clicking on the asterisk (Add Reputation) at the bottom of their post.

  10. #10
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Re: Macro to extract cell content and "rejig" columns

    I'll create a new thread for my other question then

    Could you please tel me what can I delete to remove the truncation part of the asset code? I found a way to get exactly what I needed via formulas but still need the rest of the macro to work to rejig all the columns.

    Thanks again
    Last edited by SubwAy; 09-20-2016 at 01:56 AM.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to extract cell content and "rejig" columns

    I'm not sure 100%, my untested thought is to change:
    Please Login or Register  to view this content.
    ...to this:
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Re: Macro to extract cell content and "rejig" columns

    Hi JBeaucaire,

    Apologies for the late reply, I was out of the office. Brilliant, your recommendation worked perfectly.

    Thank you
    S

+ 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. [SOLVED] Excel 2010 -- "Visual Basic" "Macros" and "Record Macro" all disabled.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2017, 06:11 AM
  2. [SOLVED] Place "X" in a cell based on tonnes across columns "weeks"
    By Iain Clarendon in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-01-2015, 09:27 AM
  3. Replies: 2
    Last Post: 03-08-2015, 09:31 AM
  4. Receiving "enable content" warning after executing "save as" code
    By phbryan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-11-2014, 12:02 PM
  5. [SOLVED] formula help: conditional format of one column based on "YES"/"NO" content of four others!
    By 10 Dollar Bill in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-20-2014, 01:59 PM
  6. Replies: 0
    Last Post: 01-09-2013, 06:52 PM
  7. Replies: 5
    Last Post: 09-19-2008, 04:02 PM

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