VBA, scroll through column looking for yellow cells

dappy

Board Regular
Joined
Apr 23, 2018
Messages
124
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I've searched but had no luck. Hopefully this is easy for someone 🥴 I need to scroll down a column an if a cell is yellow then copy that content to another column. It will always be the same column for the yellow cells and the target column would be next to it.
There are some rows in the sheet that are empty though. Is this doable?

Help much appreciated and so much thanks in advance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How are these cells being colored yellow?
Is it being done manually, or via Conditional Formatting?
What are the columns involved?
 
Upvote 0
Try this code.

You will need to change the column letter to match whatever column you want to check (you did not answer that question for me):
VBA Code:
Sub MyCopyYellowCells()
    
    Dim c As String
    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False

'   Designate which column to check
    c = "P"
    
'   Find last row in column with data
    lr = Cells(Rows.Count, c).End(xlUp).Row
    
'   Loop through all rows
    For r = 1 To lr
'       Check color of cell to see if it is yellow
        If Cells(r, c).Interior.Color = 65535 Then
'           Populate column to right
            Cells(r, c).Offset(0, 1).Value = Cells(r, c).Value
        End If
    Next r
        
    Application.ScreenUpdating = True
    
    MsgBox "Macro complete!"
    
End Sub
 
Upvote 0
Solution
That is perfect, thank you so much, you're the best! you've save me :)
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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