+ Reply to Thread
Results 1 to 20 of 20

Macro help with combining data across 2 rows (and deleting non-required rows)

  1. #1
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Cool Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    I am trying to see if there is a macro that would help me fix the layout of the data (example file attached). The system (not mine) produces the info over 2 rows, and also out of line, but I need to have it in one row.

    Currently I am just doing B5=A4, C5=B4 etc and copying the formulas down where required.

    A Couple of issues though:

    I only need the rows that show ‘accepted’ or ‘referred’ (and the corresponding rows beneath that).

    Anything that is ‘new’, ‘rejected’ or ‘arbitrator’ I need deleted (and the corresponding row below this)

    To compound this there are incidents in column A that have multiple rows (e.g. 66-68 & 73-76) so in these examples I currently manually delete everything but the most recent incident. Again is there a way for a macro to check if an incident (cell A4 is an example of an incident number) has multiple rows and keep the most recent row and delete the rows above it that relate to the same incident?

    Any help greatly appreciated

    Thanks

    Innes
    Attached Files Attached Files

  2. #2
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    The format can be achieved through a macro but will need multiple conditions to be set.

    Can you upload a sample file showing how you want your data to show?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    I've uploaded now how I would like the final layout to be.

    Thanks for getting back to me.

    Innes
    Attached Files Attached Files

  4. #4
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    In the case of row 66-68 and 73-76, they have different values in column K, so ideally only the "Accepted" and "Referred" entries would be retained right? The others would be deleted?

  5. #5
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    In the example of 66-68 all of these rows would be deleted (and therefore line 69) and none are 'accepted' or 'referered'

    In the example of 73-76 only line 76 (and therefore line 77 also) would be kept as it is the most recent entry that is either accepted or referred (could you use column C that has date-time to identify the most recent entry in macro?)

    Thanks

    Innes

  6. #6
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    So if there are 2 rows, 1 containing Accepted and the other Referred, whichever contains the latest entry would be retained, rest deleted?

  7. #7
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    Yes that's correct.

    Thanks

    Innes

  8. #8
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  9. #9
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    That worked perfectly thanks. However, I removed columns A-N from the original file thinking that when I added these back in and ran the macro it would delete these as well (Sorry, my mistake). I tried amending the code but code baffles me so I just messed it up :-(

    I've attached a tab called 'original sample file' and highlighted the columns in yellow (A-N) I removed. Is it possible to amend the macro so that rather than starting at A3 it starts at O3 but still removed all the relevant rows, does that make sense?

    Also, after it's all sorted out the rows is it possible to add some more code to insert a new column after column A and 'Text to Columns' the incident number based on a hypen (-)?

    Much appreciated if you could.

    Thanks

    Innes
    Attached Files Attached Files

  10. #10
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Try this code
    Please Login or Register  to view this content.
    You could have saved this double work by attaching a sample which matched the original file.

  11. #11
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    Sorry, I thought it would make it easier by skimming down the amount of data but lesson learned for future reference!

    I tried the new code but everything in column A-O is deleted. I've attached the ouput after the Macro is run so you can see.

    Thanks

    Innes
    Attached Files Attached Files

  12. #12
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    That's because data in columns A to N starts in row 5, while columns O onwards starts in row 4. You can delete the row only for those columns and run the macro or if you want the macro can be edited to include that part.

  13. #13
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    I tried to edit the macro to include that part but I came unstuck. Can you advise on how I would change it to include that part please?

    I would like it so that the macro checks for the most recent referred or accepted line and keeps it (and the the corresponding line beneath that) and deletes any other rows not required.

    Basically what it is doing now but including columns A-N. Is there a simple way to fix this (even if I put a random letter in A4,A6,A8 etc prior to running the macro)

    Thanks

    Innes

  14. #14
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    I didnt understand this part
    I would like it so that the macro checks for the most recent referred or accepted line and keeps it (and the the corresponding line beneath that) and deletes any other rows not required.

    Basically what it is doing now but including columns A-N. Is there a simple way to fix this (even if I put a random letter in A4,A6,A8 etc prior to running the macro)

  15. #15
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    Sorry might have over complicated it in my explanations.

    Basically, going back to the original macro, how can you amend it if we add in rows A to N so that when rows are deleted it retains the info in COLUMNS**(amended from rows) A-N?

    Thanks

    Innes
    Last edited by InnesMcc; 05-17-2013 at 02:37 AM.

  16. #16
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    So you do not want row 4 to be deleted for columns A to N so that the data in all the columns is in the same row?

  17. #17
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    Sorry for delay in replying, I was not in work over the weekend.

    I don't understand your last reply. I have attached a sample of the file I get sent to me and then a smaple of what I would like it to look like after the macro has run.

    Thanks

    Innes
    Attached Files Attached Files

  18. #18
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Let me explain again - if you run the macro that i provided you initially, you are missing out on data in columns A to N. This is because data in columns A to N starts in row 5 but for columns O onwards, it starts in row 4. This can be easily solved, if we just delete the empty cells in A4:N4 and move the remaining data up. So then A to the last column will have all the data in the same row.

    Is it easy to understand now?

  19. #19
    Registered User
    Join Date
    11-04-2011
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Hello,

    Yes it is now....apologies I'll blame it on being Monday morning.

    I've deleted A4:N4 then run the macro and all appears to be working!

    Thanks very much for everything, especially your patience!

    Regards

    Innes

  20. #20
    Administrator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,147

    Re: Macro help with combining data across 2 rows (and deleting non-required rows)

    Np, glad its working.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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