+ Reply to Thread
Results 1 to 4 of 4

VBA to move data to new worksheets based on cell value

Hybrid View

GregStewartPTC VBA to move data to new... 02-21-2018, 12:18 PM
Mumps1 Re: VBA to move data to new... 02-21-2018, 12:55 PM
GregStewartPTC Re: VBA to move data to new... 02-21-2018, 01:39 PM
Mumps1 Re: VBA to move data to new... 02-21-2018, 01:45 PM
  1. #1
    Registered User
    Join Date
    08-16-2016
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    49

    VBA to move data to new worksheets based on cell value

    I am needing to create a vba/macro to move data from one worksheet to another based on the value of a cell in a specific column. Ideally the new tabs would be named with the value that is in the cell, to make it easier to sift through once finished. Is this possible?

    I've uploaded an example worksheet. All data that is sent to me is always under the worksheet 'Supply Data'. I need to filter based on the Branch Name in Column A - create a tab with that branch name - move all info from all rows containing that branch name to the tab. If it can somehow go back and delete the data after it has been moved, or even delete the entire worksheet would be even better, if that is possible?

    I also realize I could sort this into a pivot table very easily, but because the data from Column F-M has to have a very specific custom sort for the reps to know which order to work their list from, it isn't a good option.

    Thanks in advance for any help you can provide.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: VBA to move data to new worksheets based on cell value

    Try on a copy of your file:
    Sub CreateSheet()
        Application.ScreenUpdating = False
        Dim bottomA As Long
        bottomA = Sheets("Supply Data").Range("A" & Rows.Count).End(xlUp).Row
        Dim branch As Range
        Dim ws As Worksheet
        Dim rngUniques As Range
        Sheets("Supply Data").Range("A1:A" & bottomA).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
            ("A1:A" & bottomA), Unique:=True
        Set rngUniques = Sheets("Supply Data").Range("A2:A" & bottomA).SpecialCells(xlCellTypeVisible)
        If Sheets("Supply Data").AutoFilterMode = True Then Sheets("Supply Data").AutoFilterMode = False
        For Each branch In rngUniques
            Set ws = Nothing
            On Error Resume Next
            Set ws = Worksheets(branch.Value)
            On Error GoTo 0
            If ws Is Nothing Then
                Worksheets.Add(After:=Sheets(Sheets.Count)).Name = branch.Value
                Sheets("Supply Data").Range("A1:A" & bottomA).AutoFilter Field:=1, Criteria1:=branch
                Sheets("Supply Data").Range("A1:A" & bottomA).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(branch.Value).Cells(Sheets(branch.Value).Rows.Count, "A").End(xlUp).Offset(1, 0)
                Sheets(branch.Value).Rows(1).EntireRow.Delete
                Sheets(branch.Value).Columns.AutoFit
                If Sheets("Supply Data").AutoFilterMode = True Then Sheets("Supply Data").AutoFilterMode = False
            End If
        Next branch
        Application.DisplayAlerts = False
        Sheets("Supply Data").Delete
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
     End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    08-16-2016
    Location
    Illinois, USA
    MS-Off Ver
    Office 365
    Posts
    49

    Re: VBA to move data to new worksheets based on cell value

    Thank you very much for the fast reply Mumps. This is perfect! +Rep and I'm marking solved.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: VBA to move data to new worksheets based on cell value

    You are very welcome and thanks for the rep.

+ 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. Move data based on cell value
    By vitt4300 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-30-2014, 01:21 PM
  2. Replies: 0
    Last Post: 08-11-2014, 02:38 PM
  3. [SOLVED] Macro to Move Rows to New Worksheets Based on Criteria & Then HIDE & Move Back
    By abro0821 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2014, 04:00 PM
  4. Replies: 5
    Last Post: 02-09-2014, 11:04 PM
  5. Automatically move rows of data to different worksheets based on cell criteria
    By Kaz09 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2013, 12:49 PM
  6. I need to move data from main worksheet into multiple worksheets based on a criteria
    By ksenia81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2012, 05: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