+ Reply to Thread
Results 1 to 9 of 9

copy row to other sheets depending on cell value (multiple values!)

Hybrid View

Armitage2k copy row to other sheets... 10-18-2013, 04:57 AM
AB33 Re: copy row to other sheets... 10-18-2013, 05:23 AM
Armitage2k Re: copy row to other sheets... 10-18-2013, 06:11 AM
AB33 Re: copy row to other sheets... 10-18-2013, 06:41 AM
Armitage2k Re: copy row to other sheets... 10-18-2013, 07:06 AM
AB33 Re: copy row to other sheets... 10-18-2013, 07:38 AM
Armitage2k Re: copy row to other sheets... 10-21-2013, 01:23 AM
congokin Re: copy row to other sheets... 10-25-2013, 06:58 PM
AB33 Re: copy row to other sheets... 10-26-2013, 07:01 AM
  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    copy row to other sheets depending on cell value (multiple values!)

    Hi,

    I have a worksheet with raw data and now would need to go through every single row to check if column I is holding a specific number, and if yes, copy it to another sheet. totally there are several options where I need to copy to.

    Cell value - sheet name
    2660 - Blue
    2200 - Cafe
    2230 - Marcos
    2290 - Vbar

    So basically, if column I cell content is 2230, then copy the entirerow to sheet marcos. if value is 2290 then copy to vbar, if 2660 copy to blue, etc.
    I did find several samples via google where this topic is explained, but the problem is that I have around 5000 rows of data and dont want to loop through the entire data 4 times to check one by one if there is a match...

    Any suggestions are welcome!
    Thanks,
    A2k

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: copy row to other sheets depending on cell value (multiple values!)

    Please attach a sample and will write you a faster code.

  3. #3
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: copy row to other sheets depending on cell value (multiple values!)

    My current very simple attemp for your reference.

    Sub Distributer()
    Set r = ActiveWorkbook.Sheets("temp").Range(Range("I65536").End(xlUp), Range("I2"))
    
    'Marcos Chinese Kitchen
    For Each C In r
        If C.Value = "2000" Then C.EntireRow.Copy Destination:=Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1, 0)
    Next
    For Each C In r
        If C.Value = "2030" Then C.EntireRow.Copy Destination:=Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1, 0)
    Next
    For Each C In r
        If C.Value = "2090" Then C.EntireRow.Copy Destination:=Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1, 0)
    Next
    
    end sub
    Thanks,
    A2k

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: copy row to other sheets depending on cell value (multiple values!)

    You can shorten it

    Sub Distributer()
    Set r = ActiveWorkbook.Sheets("temp").Range(Range("I65536").End(xlUp), Range("I2"))
    
    'Marcos Chinese Kitchen
    For Each C In r
        If C.Value = "2000" Then
            C.EntireRow.Copy Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1)
    
        ElseIf C.Value = "2030" Then
            C.EntireRow.Copy Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1)
    
        ElseIf C.Value = "2090" Then
            C.EntireRow.Copy Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1)
        
        End If
    Next
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: copy row to other sheets depending on cell value (multiple values!)

    hmm... well, why not, its something

    I guess there is absolutely no way for me to have an elegant solution like

    If C.Value = "2000" OR "2200" or "2290" then
    bummer.
    But thanks a lot for the help.
    A2k

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: copy row to other sheets depending on cell value (multiple values!)

    Of course you can have; I did not notice that you are copying in to the same sheet.

    Sub Distributer()
    Application.ScreenUpdating = 0
    Dim r As Range, c As Range
    Set r = ActiveWorkbook.Sheets("temp").Range(Range("I65536").End(xlUp), Range("I2"))
    
    'Marcos Chinese Kitchen
    For Each c In r
        If c.Value = "2000" Or c.Value = "2030" Or c.Value = "2090" Then
            c.EntireRow.Copy Worksheets("Marcos_Data").Range("A65536").End(xlUp).Offset(1)
        End If
    Next
    Application.ScreenUpdating = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: copy row to other sheets depending on cell value (multiple values!)

    Madly in love with you AB33,
    thanks a lot
    A2k

  8. #8
    Registered User
    Join Date
    11-03-2010
    Location
    calgary, ab
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: copy row to other sheets depending on cell value (multiple values!)

    i have a similar question but this time i need to copy a range instead of specific value
    i have a workbook with 2 worksheet "24hrData" and "PitSession". I just need to get the 0900-1430 (pit session) of the "24hrData" worksheet and transfer to "PitSession" worksheet
    I could use the code above and write for every time but i need a more efficient way to do it
    Sub Distributer()
    Application.ScreenUpdating = 0
    Dim r As Range, c As Range
    Set r = ActiveWorkbook.Sheets("24hrData").Range(Range("B65536").End(xlUp), Range("B2"))
    'Marcos Chinese Kitchen
    For Each c In r
        If c.Value = "0700" Or c.Value = "0701" Or c.Value = "0702" Or c.Value = "0703" Or c.Value = "0704" Or c.Value = "0705" Then   'I want to copy from 0700...1430 end of pit session
            c.EntireRow.Copy Worksheets("PitSession").Range("A65536").End(xlUp).Offset(1)
        End If
    Next
    Application.ScreenUpdating = True
    End Sub
    can someone help me on this?
    Last edited by congokin; 10-25-2013 at 07:11 PM.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: copy row to other sheets depending on cell value (multiple values!)

    congokin,
    You need to start your own thread. Please read forum rules.

+ 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. [SOLVED] Sorting data from a master sheet to multiple sheets depending on values in a given column
    By kodos10 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-30-2013, 05:46 AM
  2. Replies: 1
    Last Post: 05-15-2013, 09:51 PM
  3. Creating multiple sheets depending a cell count
    By burlywood66 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-02-2010, 05:25 PM
  4. Copy a range to different sheets depending on first cell contents
    By WaveOfMutilation in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 03-01-2010, 12:58 PM
  5. Replies: 1
    Last Post: 02-20-2009, 11:15 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