+ Reply to Thread
Results 1 to 13 of 13

Copy rows to different ranges of another sheet and add common data to each new row

  1. #1
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Copy rows to different ranges of another sheet and add common data to each new row

    Good Morning Forum,


    I need a code that will copy some data to a Recap sheet, but to different ranges, depending on the block the data is coming from on my main sheet.

    You will find attached a sample with the details of what I need.

    Thank you very much if you can help me with that.

    Have a great day all!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Good evening,

    attach the filled expected result workbook according to your original attachment …

  3. #3
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Re: Copy rows to different ranges of another sheet and add common data to each new row

    Hello Mark,

    Thank you very much but I can see no file??

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Tabernacle ! Je t'ai demandé de joindre le classeur avec le résultat attendu rempli …

    English version : just well read my post again, LoL !

  5. #5
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Re: Copy rows to different ranges of another sheet and add common data to each new row

    Ok

    Here you are with a few fake rows! I also removed the useless columns.

    Merci !
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    According to your last attachment a VBA starter :

    PHP Code: 
    Private Sub CommandButton1_Click()
      Const 
    7
        Dim V
    (), M%
            
    = Array([B18].End(xlUp).Row 9, [B30].End(xlUp).Row 21)
            
    Application.Max(V)
        
    With Sheets("Recap").Cells(Rows.Count1).End(xlUp)(2)
           .
    Resize(M3).Value2 = Array([F4], [E5], [E6])
           .
    Offset(, 3).Resize(V(0), C).Value2 = [A10].Resize(V(0), C).Value2
           
    .Offset(, 9).Resize(M).Interior.ColorIndex 15
           
    .Offset(, 10).Resize(V(1), C).Value2 = [A22].Resize(V(1), C).Value2
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Re: Copy rows to different ranges of another sheet and add common data to each new row

    Bonjour Marc !

    I tried your code and it works number 1!!! May I ask you if it would be a lot of work to adapt it according to the change I made to the workbook (attached) :
    I have splitted commissions and expenses for practical purposes. Yeah I know, I should have thought of it sooner… I am feeling embarrassed

    Note that the "Crea Releve" should be used to copy data to the Recap sheets.

    Thank you again for your time and your help. Je vous souhaite une excellente journée !
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Re: Copy rows to different ranges of another sheet and add common data to each new row

    Me again,

    I tried to modify your code and I am almost there but I need your help for the last difficulty. With the code below, Excel creates the maximum of rows on each sheet. Unfortunately I Don't know how to correct it. I understand that it comes from M but that's all

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Bonsoir Sybille !

    As I have a little issue with your last attachment so I have to grab another computer
    with a more recent Excel version in order to answer to your post #7 later (around 4 hours as I have a dinner now)

  10. #10
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Re: Copy rows to different ranges of another sheet and add common data to each new row

    Hello Marc,

    Bon dîner ! I just want to let you know that with your original code, I get an error 1004 message pointing to

    Please Login or Register  to view this content.
    when I try to add some new data (expenses only).

    You will find my test file attached.

    So, in order to make things clear:

    I wish to split my Recap into two spreadsheets and I need to adapt the code - Posted at 12:03

    I get an error message with the original file trying to add data (new rows) if commissions are empty.

    Thank you so much!!
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    According to the previous post (#10) attachment :

    PHP Code: 
    Private Sub CommandButton1_Click()
     Const 
    7
       Dim V
    (), M%
           
    = Array([B18].End(xlUp).Row 9, [B30].End(xlUp).Row 21)
           
    Application.Max(V)
        If 
    M Then
            With Sheets
    ("Recap").Cells(Rows.Count1).End(xlUp)(2)
                .
    Resize(M3).Value2 = Array([F4], [E5], [E6])
                 If 
    V(0Then .Offset(, 3).Resize(V(0), C).Value2 = [A10].Resize(V(0), C).Value2
                
    .Offset(, 9).Resize(M).Interior.ColorIndex 15
                 
    If V(1Then .Offset(, 11).Resize(V(1), C).Value2 = [A22].Resize(V(1), C).Value2
            End With
        End 
    If
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    According to post #7 for Feuil6 (Crea_Releve) :

    PHP Code: 
    Private Sub CommandButton1_Click()
       
    Dim VR%
           
    = Array([F4], [E5], [E6])
           
    = [B18].End(xlUp).Row 9
        
    If R Then
            With Feuil3
    .Cells(Rows.Count1).End(xlUp)(2).Resize(R10).Columns
                
    .Item("A:C").Value2 V
                
    .Item("D:I").Value2 = [A10].Resize(R6).Value2
                
    .Item(10).Interior.ColorIndex 15
                
    .Item(10).FormulaR1C1 "=RC[-2]*RC[-1]"
            
    End With
        End 
    If
           
    = [B30].End(xlUp).Row 21
        
    If R Then
            With Feuil4
    .Cells(Rows.Count1).End(xlUp)(2).Resize(R10).Columns
                
    .Item("A:C").Value2 V
                
    .Item("D:I").Value2 = [A22].Resize(R6).Value2
                
    .Item(10).FormulaR1C1 "=SUM(RC[-3]:RC[-1])*SIGN(0.1-(RC[-5]=""Facture""))"
            
    End With
        End 
    If
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  13. #13
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    125

    Re: Copy rows to different ranges of another sheet and add common data to each new row

    Good evening Marc,

    Incredible, everything works like a charm.

    Thank you very much!

+ 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. Loop through worksheets and copy data ranges into one sheet
    By mcaballero in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2015, 04:44 PM
  2. [SOLVED] Copy data from several ranges to new sheet
    By jpruffle in forum Excel General
    Replies: 1
    Last Post: 04-02-2015, 09:00 PM
  3. [SOLVED] Copy data from dynamic ranges and paste it another sheet
    By Villalobos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2015, 04:58 AM
  4. [SOLVED] Copy Ranges with Common Value to Another Workbook
    By chntnpatel in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-30-2013, 08:49 AM
  5. Copy ranges of data from Master Sheet to Slave Sheets
    By mike.haley in forum Excel General
    Replies: 0
    Last Post: 01-23-2013, 12:51 PM
  6. Search header row for common text in cells and copy below rows to new sheet
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-19-2011, 02:23 PM
  7. copy paste data with multiple selected ranges from sheet to sheet
    By sivdin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-14-2011, 02:45 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