+ Reply to Thread
Results 1 to 3 of 3

Copying a row to new sheet based on a cell value

  1. #1
    Registered User
    Join Date
    07-21-2015
    Location
    new york
    MS-Off Ver
    MS excel 2010
    Posts
    4

    Unhappy Copying a row to new sheet based on a cell value

    For sample, the code below copies all the rows in the "Materlist" sheet that contains "Brooklyn" on column E to the sheet named "Brooklyn" in the same workbook. I have a sheet named for each value on column E of the Masterlist, about 35, and would like to separate the data to it's own sheet when new data is enter in the master list. The masterlist gets updated by several people, but I have to separate the data to it's own sheet, so I am trying to make the process more efficient. I already have a code to create a new sheet for every unique value in column E of the master list, now I want it to move that data to the sheet it created. The code below works but it is not automatic. How can I make it so it moves data(entire row) for all values on column E to the sheet named after that value.


    Sub Cheezy()
    Dim xRg As Range
    Dim xCell As Range
    Dim I As Long
    Dim J As Long
    I = Worksheets("Masterlist").UsedRange.Rows.Count
    J = Worksheets("Brooklyn").UsedRange.Rows.Count
    If J = 1 Then
    IF Application.WorksheetFunction.CountA(Worksheets("Brooklyn").UsedRange) = 0 Then J = 0
    End If
    Set xRg = Worksheets("Masterlist").Range("E1:E" & I) On Error Resume Next
    Application.ScreenUpdating = False
    For Each xCell In xRg If CStr(xCell.Value) = "Brooklyn" Then xCell.EntireRow.Copy Destination:=Worksheets("Brooklyn").Range("A" & J + 1) xCell.EntireRow.Delete J = J + 1
    End If
    Next Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Copying a row to new sheet based on a cell value

    Hi len2088,

    First, could you use Code Tags please:
    Instead of posting something like this:

    Sub Cheezy()
    '
    End Sub

    Use the # editor icon , to get BB Code Code tags, or add those Tag pairs manually like this:
    [CODE]Sub Cheezy()
    '
    End Sub[/CODE]

    That has the effect that when posted, the code comes out in a nice code window

    Have a go at Editing your Post #1 please to add those tags and then Save to repost. ( Note: there is a Forum Software Bug which sometime cause the original contents to vanish without trace when you hit the Edit button, so you might want to copy the post contents to the clipboard before you hit the Edit button, so that you can re-paste in the case that the original contents vanish unexpectedly. )
    _.______

    Second, When you get time, please read the forum rules – all the jem on stuff like code tags is there:
    http://www.excelforum.com/forum-rule...rum-rules.html
    http://www.excelforum.com/forums-rules/
    http://www.excelforum.com/developmen...ml#post4606484


    _.___________

    Finally, to your request for help:
    There are lots of ways to achieve what you want.
    It would be most helpful if you could give us some sample data, reduced in size, and you can make the data up if you like so as not to give sensitive data. But keep the data type representative of typical data types and formats and choose it carefully so that it covers all typical scenarios in the data.

    Here is some jem on getting data across to us:_.....
    https://www.excelforum.com/developme...ml#post4532042
    _.....The simplest thing to do would be to upload us two files, the Before, and After
    The Before is your reduced size sample data. The After is the modified Before, showing exactly what you want the code to do. In other words, you do manually in the After what you want the code to do.
    And say again exactly what action should cause that code to run.

    Alan
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,382

    Re: Copying a row to new sheet based on a cell value

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Copying a row to another sheet based on a cell value from a list
    By r.whilock in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2015, 08:27 PM
  2. Copying a portion of a row based on cell criteria to another sheet
    By lucky.vjn in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-20-2015, 04:05 PM
  3. Copying a selected row to another sheet based on cell value
    By Ixorian in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-23-2014, 01:27 PM
  4. Copying data from one sheet to another based on cell color
    By Redcarn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2012, 03:16 AM
  5. Copying row based off cell value to a sheet of the same name
    By hambly in forum Excel Programming / VBA / Macros
    Replies: 52
    Last Post: 11-23-2011, 06:12 PM
  6. Replies: 4
    Last Post: 03-22-2011, 02:26 AM
  7. copying from one sheet to another based on cell value
    By tinkerbelle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2010, 06:51 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