+ Reply to Thread
Results 1 to 17 of 17

Copying merged cells (3 cells) based on conentes of any of 3 cells to right

  1. #1
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I wish to copy a merged cell (3 cells) based on if only 1 of 3 cells to the right contain "X". if the top cell does not contain "X" than the merged cell is not copied. Also, is therea more elegant to copy 3 columns at a time rather than do one at a time as my code shows:

    Sub CopyICUCAPU()
    '
    ' CopyICUCAPU Macro
    '
    Dim i As Integer

    For i = 5 To 29 Step 3
    If Sheets("ICU").Range("L" & i).Value = "X" And Sheets("ICU").Range("A" & i).Value <> "" Then
    Sheets("CAPU summary").Range("A" & i).End(xlUp).Offset(1).Value = Sheets("ICU").Range("A" & i).Value
    End If
    Next i

    For i = 5 To 29 Step 3
    If Sheets("ICU").Range("L" & i).Value = "X" And Sheets("ICU").Range("B" & i).Value <> "" Then
    Sheets("CAPU summary").Range("B" & i).End(xlUp).Offset(1).Value = Sheets("ICU").Range("B" & i).Value
    End If
    Next i

    For i = 5 To 29 Step 3
    If Sheets("ICU").Range("L" & i).Value = "X" And Sheets("ICU").Range("c" & i).Value <> "" Then
    Sheets("CAPU summary").Range("c" & i).End(xlUp).Offset(1).Value = Sheets("ICU").Range("c" & i).Value
    End If
    Next i

    For i = 5 To 29
    If Sheets("ICU").Range("L" & i).Value = "X" Then
    Sheets("CAPU summary").Range("l" & i).Value = Sheets("ICU").Range("d" & i).Value
    End If
    Next i
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    To do three columns at once, you can do this:
    Please Login or Register  to view this content.
    Also, wrap your code in [CODE] tags, like above. I'm having trouble visualizing what you're talking about with merged cells. Can you provide a sample worksheet?

  3. #3
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    Here is a shot of the merged cells. I only want to copy if value = "X" in column L (one of 3 cells aligned with name. I also want to copy column E if there is an "X" in on of the 3 columns but it has to line up with the correct name. I have not tried the code yet but will this afternoon.

    Capture.PNG

  4. #4
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I tried the code and it only copied the first column, not all 3. Also, did my screen shot make it to my last post so you could get a view of my spreadsheet.

    Thanks

  5. #5
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I see your screen shot. I'm still unclear on what you want to happen.

    Sent from my SPH-D710 using Tapatalk
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

  6. #6
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I want to copy first 3 columns to a summary sheet but only want to copy those columns if there is an "X" in on the 3 cells in coluumn L i.e. name in Column A, cell 5 to 7 does not have any "X" in Column L row 5, 6 and 7 - however name in Column A, cell 8 to 10 has at least 1 "X" in COlumn L row 8, 9 and 10 so I want to copy that name and 2 other columns. There are multiple sheets that I will also add so that I will have the summary sheet only with names that Hav an "X" in column L. Does this help.

  7. #7
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I think I understand what you want. First, my advice is to stay away from merged cells. They cause all sorts of trouble. Second, this is too complicated for me to do in my head. If you give me a sample workbook, I'll see what I can do.

  8. #8
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I have attached a sample file. I did not realize that merged cells create problems. I can modify my design to handle that but the merged cells make it much easier.
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    Is this what you wanted?
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    It is really close but I only want those cells in Column D copied that have an "X" in Column L. I have attached what I am looking for.

    Many thanks for you help. I am new to macros and am trying to learn them but this is a difficult one for me.
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    How about this?
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    It is copying all the correct information over which is great, but the information should be copied in the first empty row starting with A5 - this will be necessary because I will apply the same macro to the other sheets in this workbook. Hopefully, I will be able to accomplish that after this first one is perfect. I am trying to follow your code and realize that I have a lot to learn. Thanks for all your help

  13. #13
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    I saw that you were doing that, which is why I had my first version copy to the next available cell. But then I noticed that your code wouldn't copy to the next available cell anyway. If you ran your original code on another sheet, it would just overwrite what you already had with the exact same things.

    There is a better way to do this if you don't care so much about how it looks.

  14. #14
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    If there is a better way to do what I am attempting, than I would gladly accept that. The summary only has contain the necesaary data that have an "X" in column L.

    Thanks for helping me through this and I am looking forward to your better way - currently, this is beyond my capabilitites.

  15. #15
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    Here it is. I removed most of the merged cells. I think it should be just as functional, if not more, because it allows for more than 3 ulcer locations per patient and doesn't even require that they are all recorded in adjacent rows. I did it two ways. CopyICUCAPUv3 does it with loops, while the final way does it with autofilter. This should be faster (though with small data sets it won't be noticeable).
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    01-26-2014
    Location
    Ipswich, MA
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    Thank-you so much, it does work. One interesting thing I found is that running CopyICUCAPUv3, it will not recognize a lower case x. However, CopyICUCAPU does recognize the lower case x. I will now work to add the other tabs to te summary.

    Thanks again

  17. #17
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Copying merged cells (3 cells) based on conentes of any of 3 cells to right

    You're welcome. Glad I could help.

+ 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. Copying into merged cells adds unwanted tabs
    By net2chris in forum Excel General
    Replies: 5
    Last Post: 08-15-2013, 08:07 PM
  2. Replies: 1
    Last Post: 06-28-2012, 11:53 AM
  3. Copying values of merged cells
    By ffffloyd in forum Excel General
    Replies: 9
    Last Post: 04-09-2009, 03:57 AM
  4. Copying Merged Cells
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2008, 03:41 PM
  5. [SOLVED] Copying a column of single cells into a column of merged cells
    By clairejane_99@hotmail.com in forum Excel General
    Replies: 1
    Last Post: 08-16-2006, 08:20 AM

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