Results 1 to 19 of 19

Copy data to new workbooks based on cell value

Threaded View

corndogs Copy data to new workbooks... 10-25-2019, 03:15 PM
bakerman2 Re: Copy data to new... 10-25-2019, 08:35 PM
corndogs Re: Copy data to new... 10-29-2019, 11:06 AM
Marc L Hi, try this ! 10-29-2019, 12:20 PM
corndogs Re: Hi, try this ! 10-31-2019, 12:48 PM
bakerman2 Re: Copy data to new... 10-31-2019, 01:25 PM
corndogs Re: Copy data to new... 10-31-2019, 01:55 PM
bakerman2 Re: Copy data to new... 10-31-2019, 09:28 PM
corndogs Re: Copy data to new... 11-01-2019, 11:11 AM
bakerman2 Re: Copy data to new... 11-01-2019, 01:07 PM
corndogs Re: Copy data to new... 11-01-2019, 01:47 PM
Marc L So you will have same issue... 11-01-2019, 02:00 PM
corndogs Re: Copy data to new... 11-01-2019, 04:10 PM
Marc L 'Me' is a reference to the... 11-01-2019, 04:28 PM
bakerman2 Re: Copy data to new... 11-01-2019, 08:39 PM
Marc L Maybe an issue : ... 11-01-2019, 08:59 PM
bakerman2 Re: Copy data to new... 11-01-2019, 09:45 PM
Marc L Oh no, your previous answer... 11-01-2019, 10:11 PM
Marc L Instead of an easier / safer... 11-01-2019, 11:02 PM
  1. #1
    Registered User
    Join Date
    08-22-2019
    Location
    Washington
    MS-Off Ver
    __
    Posts
    7

    Lightbulb Copy data to new workbooks based on cell value

    Hola

    This is my first post but I've been to this site many times for useful information so thank you! In fact, the code below is based on some code I found here I believe.

    My intention is to create x number of workbooks based on values in column k (RepAssign). X is precisely my hang up. I've been able to write code to filter by values in a column to copy the filtered data to a new workbook, however, the values were static in the past.

    My new code is splitting out records evenly based on user input, a prompt asks the user how many ways to split the rows. For testing, I went with 3 so I'd like to end up with 3 new workbooks for example, leaving the original/source workbook as is. It could be anywhere from 2 to 20 workbooks being created, again depending on user input. See attached for sample data.

    Existing code;

    Sub test()
    
        'Determine last column, add label
        GetUsedColumns
        ActiveSheet.Cells(1, UsedColumns + 1) = "RepAssign"
        
        'Prompt user to choose how many splits are needed
        Dim RepAssign As Long
        RepAssign = InputBox(Prompt:="How many Rep Assignments?", _
                Title:="Rep Assign", Default:="")
        
        'Split records evenly and label assign 1, 2, 3 etc
        Dim recCount As Long
        Dim evenDiv As Long
        Dim extraRecs As Long
        Dim h As Long 'i
        Dim j As Long 'j
        
        GetUsedColumns
        h = 1
        
        Application.ScreenUpdating = False
         
        With ActiveSheet
             'Calculate splits
             GetUsedRows
             recCount = UsedRows - 1
             extraRecs = recCount Mod RepAssign
             evenDiv = (recCount - extraRecs) / RepAssign
            
        Do While h < UsedRows
                'Every team gets at least the same amount
                For j = 1 To evenDiv
                     h = h + 1
                     .Cells(h, UsedColumns).Value = RepAssign
                 Next j
                
                 'Check if uneven amount, and if so, add a line
                If j = evenDiv + 1 And extraRecs > 0 Then
                     h = h + 1
                     .Cells(h, UsedColumns).Value = RepAssign
                     extraRecs = extraRecs - 1
                 End If
                 'Next team queued up
                 RepAssign = RepAssign - 1
             Loop
        
        End With
        Application.ScreenUpdating = True
            
        MsgBox "Done!"
            
    End Sub
    Thanks!
    Attached Files Attached Files
    Last edited by corndogs; 10-29-2019 at 11:04 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy Range from Workbooks in folder based on Cell Value
    By Cannon26 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2019, 02:07 PM
  2. 2 excel workbooks, same headers, copy data based on criteria
    By imbigsis56pa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-23-2019, 11:06 PM
  3. [SOLVED] Copy/paste data between workbooks based on criteria in a column.
    By PaulM100 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2019, 11:38 AM
  4. copy data between worksheets from different workbooks based on column name
    By dhroark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2019, 02:40 PM
  5. [SOLVED] Copy and pasting rows to specified workbooks/sheets based on cell value.
    By darrenpinto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2018, 02:39 AM
  6. Macro to copy data from other workbooks based on cell value
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-16-2013, 12:53 AM
  7. [SOLVED] Macro to copy row data based on a condition from several workbooks.
    By Ilikeideas in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 04-01-2013, 04:09 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