+ Reply to Thread
Results 1 to 16 of 16

VBA Copy rows with format to another sheet if cells value matches

  1. #1
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    VBA Copy rows with format to another sheet if cells value matches

    Hi,

    need some help to match and copy matched with neighbor rows (with formatting) to another sheet?

    Sheet1
    In Row ----> D2:P3 ------> the header
    In column--> D3:D12 ----> string #1 -> matched
    In Range --> I14:M14 ----> string #2 -> to be matched

    If range I14:M14 matches D2:D12
    Then
    paste to sheet 2 the cells matched including neighboring row with the formatting ?

    Example : Let say that range I14:M14 have value -> 1,3,5,7,9 <-and these values matched the values located in D3, D5, D7, D9, D11
    Then
    Paste the Header D2:P3
    paste D3:P3 to B3 sheet2 (including the formatting)
    paste D5:P5 to B4 sheet2 (including the formatting)
    paste D7:P7 to B5 sheet2 (including the formatting)
    paste D9:P9 to B6 sheet2 (including the formatting)
    paste D11:P11 to B7 sheet2 (including the formatting)


    Thanks

    Appreciated!

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    It will be very helpful to join an Excel file: Just change the data (for personal issue) but keep layout and format.
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    In Row ----> D2:P3 ------> the header
    In column--> D3:D12 ----> string #1 -> matched
    There is not overlapping in D3 ??
    Last edited by PCI; 05-27-2018 at 02:50 AM.

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    paste D3:P3 to B3 sheet2 (including the formatting)
    It is B3 in sheet2 because this the first row avaliable in column B ?

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    Let's assume header is in D2:P2
    and data to be paste in sheet2 in column"B" in the first free row
    Try next code
    Please Login or Register  to view this content.
    Last edited by PCI; 05-27-2018 at 03:12 AM.

  6. #6
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hi PCI,

    Thanks for your fast reply, and i'm sorry that early morning i didn't Upload the sample sheet.
    Right after my first post My Internet came down due to storm and heavy rain that is actually across Florida

    But here is the sample attached.

    Thanks

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hello, here your comment from the file

    PHP Code: 
    NoteI ran the code 2 times And indeed is Nice that 2nd report is copyng  at the bottom  (and NOT pasting on top of first one 
    Well, the second run is already pasted after the first one, at the bottom of the first one
    See sheet Test

  8. #8
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hi PCI

    Yes!, Exactly as Need it!!

    The note was a compliment

    Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    You are welcome, thank you to see for the rep

  10. #10
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hi PCI.


    I test the code in a sample file and it work perfect as long the range from sheet 1 is values. (no formulas)

    i copied and execute the code on the WS where values on sheet 1 are produced by formulas
    (sumproduct, countif, etc,etc).

    the code copy formulas instead from Sheet 1 to Sheet 2

    question : What snipped (or what line) do i have to change in order to copy that values (produced by formulas) with the conditional formats to sheet 2?

    Appreciate and Thank you so much

  11. #11
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    Can you attach a short Excel sample, it helps for debuging

  12. #12
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hi PCI

    I'm going to work right now, but i'll try to to attachach after work or from my work.
    (the original file is Huge, over 10 mb)

    Bu to give you an example this is the output displayed on Sheet 2

    Output.png

    Note :
    I removed a line of code in order to be displayed as in the pic
    but it no make no difference.
    Please see the formula bar is showing that on Cell have an IF Formula

    Please Login or Register  to view this content.
    Thanks !

  13. #13
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    See next code
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hi PCI

    I modified the code a lil bit and i'm getting the output very close as need it.

    Code was pasting the values but no the Formatting, so I replaced the lines:
    Please Login or Register  to view this content.
    By these two lines:
    Please Login or Register  to view this content.
    and i disabled the first End(3)(2)
    Please Login or Register  to view this content.

    Thank you so much, your new code make me see what lines to change.

    Thanks you, Appreciated !!

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA Copy rows with format to another sheet if cells value matches

    Good, you did what needs to be done concerning the format.
    About the last update
    HRg.Copy Destination:=Sheets(WS2Name).Cells(Rows.Count, "B").End(3)(2)
    if the header is at the right place good but take care, the " End(3)(2) " is used to determine what is the first free cell after the last cell, here in column "B".
    So just make manipulations to be sure it is Okay
    Thanks also to see for the Rep

  16. #16
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: VBA Copy rows with format to another sheet if cells value matches

    Hi PCI,

    Thanks for the Info about the (3)(2).
    Is working good But I been manipulating because i want to paste starting Row 3 (actually start pasting in row 2)

    I change to 3,3 - 3,1 - 1,3 -1,2 - 1,3
    and in 1 case it print one rows yes (next empty) or it copy doble, or each row repeated twice.
    but Not starting row 3 (as i would like), But is not big deal.

    Thanks!!

+ 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] Copy Column A data to Sheet 2 where rows matches Sheet 2 headers
    By SCDE in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2015, 12:14 AM
  2. [SOLVED] Searching Values that Follow a Specific Format and Copy Rows to a New Sheet
    By aviatecar in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2014, 07:11 AM
  3. Copy diff cells of a sheet & paste in a NEW row below previously filld rows of other sheet
    By shubhashishdubey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2014, 12:36 AM
  4. need VBA code to copy Certian Cells from one sheet to another in same format
    By splash_b in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2014, 01:50 AM
  5. Replies: 0
    Last Post: 01-08-2013, 11:34 PM
  6. Compare rows, cut matches to sheet, delete original rows
    By somesoldiers in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2010, 11:42 AM
  7. Replies: 1
    Last Post: 10-30-2009, 10:58 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