Sub Test()
Dim I As Integer
For I = 2 To 6
Sheet1.Range("A" & I & ":Q" & I).Copy Sheets(I).Range("A" & Sheets(I).Cells(Rows.Count, "B").End(xlUp).Row + 1)
Next I
End Sub

Sub TransferData()
Dim nCount As Integer
Dim myRange
Dim xRow As Long
Dim lastRow As Long
Dim ws As Worksheet
'Where is the data to split out?
Set myRange = Worksheets("Main Data").Range("A2:Q10")
Application.ScreenUpdating = False
For xRow = 1 To myRange.Rows.Count
'Split things out based on number of N in range
nCount = WorksheetFunction.CountIf(myRange.Rows(xRow).Range("M1:Q1"), "N")
Set ws = Nothing
Select Case nCount
Case 1
Set ws = Worksheets("ONE")
Case 2
Set ws = Worksheets("TWO")
Case 3
Set ws = Worksheets("THREE")
Case 4
Set ws = Worksheets("FOUR")
Case 5
Set ws = Worksheets("FIVE")
Case Else
'If 0, what do we do?
End Select
If Not ws Is Nothing Then
With ws
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Error check
If lastRow = 1 Then
lastRow = 2
End If
myRange.Rows(xRow).Copy .Cells(lastRow, "A")
End With
End If
Next xRow
Application.ScreenUpdating = True
End Sub
Hello Noel
What is the logic of the process of copying?
How can you determine which row to go to specific sheet .. what is the basis for the sheets?
It is better to attach your expected results
Try this
Code:Sub Test() Dim I As Integer For I = 2 To 6 Sheet1.Range("A" & I & ":Q" & I).Copy Sheets(I).Range("A" & Sheets(I).Cells(Rows.Count, "B").End(xlUp).Row + 1) Next I End Sub
Hi Noel, and welcome to the forum!
Rather than trying to detect color, we can use the same rule that the Conditional Formatting it using to determine where to put the info.
This macro will append data from the first sheet onto the other sheets (won't write over previous data)
Code:Sub TransferData() Dim nCount As Integer Dim myRange Dim xRow As Long Dim lastRow As Long Dim ws As Worksheet 'Where is the data to split out? Set myRange = Worksheets("Main Data").Range("A2:Q10") Application.ScreenUpdating = False For xRow = 1 To myRange.Rows.Count 'Split things out based on number of N in range nCount = WorksheetFunction.CountIf(myRange.Rows(xRow).Range("M1:Q1"), "N") Set ws = Nothing Select Case nCount Case 1 Set ws = Worksheets("ONE") Case 2 Set ws = Worksheets("TWO") Case 3 Set ws = Worksheets("THREE") Case 4 Set ws = Worksheets("FOUR") Case 5 Set ws = Worksheets("FIVE") Case Else 'If 0, what do we do? End Select If Not ws Is Nothing Then With ws lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'Error check If lastRow = 1 Then lastRow = 2 End If myRange.Rows(xRow).Copy .Cells(lastRow, "A") End With End If Next xRow Application.ScreenUpdating = True End Sub
Sub TransferData()
Dim nCount As Integer
Dim myRange
Dim xRow As Long
Dim lastRow As Long
Dim ws As Worksheet
'Where is the data to split out?
Set myRange = Worksheets("Main Data").Range("A2:Q355")
Application.ScreenUpdating = False
For xRow = 1 To myRange.Rows.Count
'Split things out based on number of N in range
nCount = WorksheetFunction.CountIf(myRange.Rows(xRow).Range("M1:Q1"), "N")
Set ws = Nothing
Select Case nCount
Case 1
Set ws = Worksheets("ONE")
Case 2
Set ws = Worksheets("TWO")
Case 3
Set ws = Worksheets("THREE")
Case 4
Set ws = Worksheets("FOUR")
Case 5
Set ws = Worksheets("FIVE")
Case Else
'If 0, what do we do?
End Select
If Not ws Is Nothing Then
With ws
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
myRange.Rows(xRow).Copy .Cells(lastRow, "A")
End With
End If
Next xRow
Application.ScreenUpdating = True
End Sub
Oops, I goofed! I forgot to add 1 to the last row...it was just pasting into row 2 again and again.
Corrected code
Code:Sub TransferData() Dim nCount As Integer Dim myRange Dim xRow As Long Dim lastRow As Long Dim ws As Worksheet 'Where is the data to split out? Set myRange = Worksheets("Main Data").Range("A2:Q355") Application.ScreenUpdating = False For xRow = 1 To myRange.Rows.Count 'Split things out based on number of N in range nCount = WorksheetFunction.CountIf(myRange.Rows(xRow).Range("M1:Q1"), "N") Set ws = Nothing Select Case nCount Case 1 Set ws = Worksheets("ONE") Case 2 Set ws = Worksheets("TWO") Case 3 Set ws = Worksheets("THREE") Case 4 Set ws = Worksheets("FOUR") Case 5 Set ws = Worksheets("FIVE") Case Else 'If 0, what do we do? End Select If Not ws Is Nothing Then With ws lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 myRange.Rows(xRow).Copy .Cells(lastRow, "A") End With End If Next xRow Application.ScreenUpdating = True End Sub
You're very welcome.
Probably. Can you paste a picture of what you mean (would like to see)?
Sub TransferData()
Dim nCount As Integer
Dim myRange
Dim xRow As Long
Dim lastRow As Long
Dim ws As Worksheet
'Where is the data to split out?
Set myRange = Worksheets("Main Data").Range("A2:Q355")
Application.ScreenUpdating = False
For xRow = 1 To myRange.Rows.Count
'Split things out based on number of N in range
nCount = WorksheetFunction.CountIf(myRange.Rows(xRow).Range("M1:Q1"), "N")
Set ws = Nothing
Select Case nCount
Case 1
Set ws = Worksheets("ONE")
Case 2
Set ws = Worksheets("TWO")
Case 3
Set ws = Worksheets("THREE")
Case 4
Set ws = Worksheets("FOUR")
Case 5
Set ws = Worksheets("FIVE")
Case Else
'If 0, what do we do?
End Select
If Not ws Is Nothing Then
With ws
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
myRange.Rows(xRow).Copy .Cells(lastRow, "A")
'Renumber rows
.Cells(lastRow, "A").Value = lastRow - 1
End With
End If
Next xRow
Application.ScreenUpdating = True
End Sub
Thanks. Code changed slightly
Code:Sub TransferData() Dim nCount As Integer Dim myRange Dim xRow As Long Dim lastRow As Long Dim ws As Worksheet 'Where is the data to split out? Set myRange = Worksheets("Main Data").Range("A2:Q355") Application.ScreenUpdating = False For xRow = 1 To myRange.Rows.Count 'Split things out based on number of N in range nCount = WorksheetFunction.CountIf(myRange.Rows(xRow).Range("M1:Q1"), "N") Set ws = Nothing Select Case nCount Case 1 Set ws = Worksheets("ONE") Case 2 Set ws = Worksheets("TWO") Case 3 Set ws = Worksheets("THREE") Case 4 Set ws = Worksheets("FOUR") Case 5 Set ws = Worksheets("FIVE") Case Else 'If 0, what do we do? End Select If Not ws Is Nothing Then With ws lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 myRange.Rows(xRow).Copy .Cells(lastRow, "A") 'Renumber rows .Cells(lastRow, "A").Value = lastRow - 1 End With End If Next xRow Application.ScreenUpdating = True End Sub