transfer selected data by colour and move to another sheet

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi, good morning. Hope you are all well? please can you help me I have the code below where I am trying to transfer data from sheet1 to sheet2, but it has to be data that ihas coloured rows in red and green for example, and then to transfer the whole row from A - V. then to shift cells up and remove the blanks, I have tried code below but getting errors, hope you can help?
Code:
Sub copy_paste_based_on_cell_interior_rgb()
    Const blue As String = "R:0 G:128 B:0"
    Const purple As String = "R:255 G:0 B:0"
    Dim i As Long
    
    With Worksheets("Sheet1")
        For i = 4 To .Range("A5" & .Rows.Count).End(xlUp).Row
            Select Case rgb_valz(.Range("A" & i))
                Case blue, purple
                    .Range("A" & i & ":V" & i).Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
                    .Range("A" & i).Interior.Color = RGB(255, 0, 255)
            End Select
        Next i
    End With
End Sub

Public Function rgb_valz(rng As Range) As String
    rgb_valz = _
        "R:" & rng.Interior.Color Mod 256 & _
        " G:" & (rng.Interior.Color Mod 256 ^ 2) \ 256 & _
        " B:" & rng.Interior.Color \ 256 ^ 2
End Function
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try
Code:
For i = 4 To .Range("A" & .Rows.Count).End(xlUp).Row
 
Upvote 0
that's worked great, thank you, how do I remove the data transferred from sheet1? and move empty cells up in sheet1? thank you again for the help
 
Upvote 0
Hi thanks for the reply back, is there no way to do it in code at all please? hope you can advise?
 
Upvote 0
You do it like
Code:
   With Worksheets("Sheet1")
      For i = .Range("A5" & .Rows.Count).End(xlUp).Row To 4 Step -1
      Select Case rgb_valz(.Range("A" & i))
         Case blue, purple
            .Range("A" & i & ":V" & i).Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
            .Rows(i).Delete
         End Select
      Next i
   End With
Note that when deleting rows you need to loop from bottom up.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top