Copy paste if cell is red

arcaidius

Board Regular
Joined
Dec 4, 2018
Messages
97
I have 4 columns with conditional formatting to fill red if values are duplicate.
I want to make a VBA code to copy all the cells that are red and paste them into 4 new columns.
So all red colored cells in column A can get pasted to column G, Column B to H, C to I, D to J.

Been scouring the internet for hours and can't make anything I've found work, please help.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Which columns cells are red just column A or all 4 columns? are the cells being copied based on column A for the other columns?
To detect cells colored with conditional formatting you need to use .DisplayFormat but to use that then you need to know exactly what shade of red you have.
To find out what shade you have select one of the colored cells and run the code below and make a note of the number returned.
VBA Code:
Sub xxxxx()
MsgBox ActiveCell.DisplayFormat.Interior.Color
End Sub

Please note that DisplayFormat only came in later versions of Excel (2010 onwards) and you haven't updated your account with the version you are using (I would suggest that you do so as it affects the answers you receive in threads).
 
Upvote 0
It is 3 or RGB 255, 0, 0,

It will be random cells from all 4 columns will be red.

For an example column A has 2,000 unique part numbers. The next 3 columns should not have the same part numbers but sometimes they do. The quantity in each column will not be the same.

So I would like the results showing which numbers are duplicated in each column so I can go back and fix the original documents the record set is from.
 
Upvote 0
Try the code below
VBA Code:
Sub arcaidius()
    Dim myCell As Range
    Application.ScreenUpdating = False
    For Each myCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
        If myCell.DisplayFormat.Interior.Color = 255 Then myCell.Offset(, 6).Value = myCell.Value
        If myCell.Offset(, 1).DisplayFormat.Interior.Color = 255 Then myCell.Offset(, 7).Value = myCell.Offset(, 1).Value
        If myCell.Offset(, 2).DisplayFormat.Interior.Color = 255 Then myCell.Offset(, 8).Value = myCell.Offset(, 2).Value
        If myCell.Offset(, 3).DisplayFormat.Interior.Color = 255 Then myCell.Offset(, 9).Value = myCell.Offset(, 3).Value
    Next
End Sub
 
Upvote 0
Solution
I added this to the end and it will do
VBA Code:
On Error Resume Next
  Columns("B").SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp

Nice name for the Sub by the way, and thanks a lot.
 
Upvote 0

Forum statistics

Threads
1,216,087
Messages
6,128,740
Members
449,466
Latest member
Peter Juhnke

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