Searching for cells with specific background color, then pulling data from the same rows?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Happy Friday!

I have this code that searches the range CalendarFloorsColumn for cells whose background color is red. It takes the data it finds in those cells and copies it to a column on another sheet called BoiseRequests.

What I need to do is have it copy additional data from columns B and D from the same row as the found red cells.

If there's a red cell in row 500 of the CalendarFloorsColumn range it would copy the data from that cell as well as the data from B500 and D500 to cell A1, A2 and A3 of the BoiseRequests sheet. The next red cell found would copy data to the next row down (B1, B2 and B3) on BoiseRequests and so on. make sense?

Here's my fabulous code...

VBA Code:
Sub BoiseRequests()
    Dim MR As Excel.Range
    Dim rngCell As Excel.Range
    Dim rngCount As Long
    
    Set MR = Sheets("Calendar").Range("CalendarFloorsColumn")
    
    rngCount = 1
    
    For Each rngCell In MR
        If rngCell.DisplayFormat.Interior.Color = RGB(255, 0, 0) Then
            Sheets("BoiseRequests").Range("A" & rngCount) = rngCell.Value
            rngCount = rngCount + 1
        End If
    Next rngCell
End Sub
 
Ok, how about
VBA Code:
Sub BoiseRequests()
    Dim MR As Excel.Range
    Dim rngCell As Excel.Range
    Dim rngCount As Long
    Dim Ws As Worksheet
   
    Set Ws = Sheets("Calendar")
    Set MR = Ws.Range("CalendarFloorsColumn")
   
    rngCount = 1
   
    For Each rngCell In MR
        If rngCell.DisplayFormat.Interior.Color = RGB(255, 0, 0) Then
            With Sheets("BoiseRequests").Range("A" & rngCount)
               .Value = rngCell.Value
               .Offset(, 1).Resize(, 2).Value = Array(Ws.Range("B" & rngCell.Row).Value, Ws.Range("D" & rngCell.Row).Value)
            End With
            rngCount = rngCount + 1
        End If
    Next rngCell
End Sub

Working great! Thanks.
 
Upvote 0

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
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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