+ Reply to Thread
Results 1 to 3 of 3

Duplicate Rows from Total sheet into individual sheets via variable data in column

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2012
    Location
    Albany,NY
    MS-Off Ver
    Excel 2010
    Posts
    2

    Duplicate Rows from Total sheet into individual sheets via variable data in column

    I've attached an example, but basically I need to copy something entered in the Total Jobs sheet by using the Store column into the matching Store Sheet. I want to keep everything in the total sheet though, so it's just duplicating. So if Row 5 was the first "Store2" it would populate the correct info under the headers (Row 5) in the individual sheets. Any help I would greatly appreciate. Thanks for your time.

    Nate
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    04-25-2012
    Location
    Albany,NY
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Duplicate Rows from Total sheet into individual sheets via variable data in column

    Or if it's easier to do it vice versa that could work as well.... meaning you could enter values into individual worksheets and then it would auto-populate the Total Jobs sheet. Thanks.

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Duplicate Rows from Total sheet into individual sheets via variable data in column

    See notes in my signature for how to implement. Hope this helps.

    Sub MoveToIndy()
    
    Dim wsTotal As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim rngCell As Range, rngSource As Range, rngDest1 As Range
    Dim rngDest2 As Range, rngToCopy As Range
    Dim lngLastCol As Long
    
    Set wsTotal = ActiveWorkbook.Sheets("Total Jobs")
    Set ws1 = ActiveWorkbook.Sheets("Store1")
    Set ws2 = ActiveWorkbook.Sheets("Store2")
    
       With Application
          .ScreenUpdating = False
          .EnableEvents = False
          .Calculation = xlCalculationManual
       End With
    
          With wsTotal
             Set rngSource = .Range("B2", .Range("B2").End(xlDown))
             lngLastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
          End With
       
             For Each rngCell In rngSource
                With wsTotal
                   Set rngToCopy = .Range(.Cells(rngCell.Row, 1), .Cells(rngCell.Row, lngLastCol))
                End With
                   If rngCell.Value = "Store1" Then
                      With ws1
                         Set rngDest1 = .Range("B20000").End(xlUp).Offset(1, -1).Resize(1, lngLastCol)
                      End With
                      rngDest1.Value = rngToCopy.Value
                   Else
                      With ws2
                         Set rngDest2 = .Range("B20000").End(xlUp).Offset(1, -1).Resize(1, lngLastCol)
                      End With
                      rngDest2.Value = rngToCopy.Value
                   End If
             Next
    
       With Application
          .ScreenUpdating = True
          .EnableEvents = True
          .Calculation = xlCalculationAutomatic
       End With
    
    End Sub
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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