VBA - Document particular cells Value, Address and Heading to new sheet

Anbuselvam

Board Regular
Joined
May 10, 2017
Messages
97
Dear All

Find the below dropbox linked sheet, In that, I want to find the yellow-coloured cells and it must be documented to the new sheet with its value, cell address and the Heading of the same.

For that, I tried below code and I got error 438


Note: Similar question posted in chandoo.org and the link is below for your information


VBA Code:
Option Explicit

Sub SelectColoredCells()
    Dim Sh As Worksheet
    Dim rCell As Range, PDate As Range
    Dim lColor As Long, r As Long
    Dim rColored As Range
    Dim High As Date
    
    Application.ScreenUpdating = False
    ' Create a new sheet
    Set Sh = Worksheets.Add
    lColor = RGB(255, 255, 0)

    Set rColored = Nothing
    For Each rCell In Sheet9.Range("A7:BD800")
        If rCell.Interior.Color = lColor Then
            If rColored Is Nothing Then
                Set rColored = rCell
            Else
                Set rColored = Union(rColored, rCell)
            End If
        End If
    Next
If rColored Is Nothing Then
        MsgBox "No cells match the color"
    Else
 With Sh
        'Put header "Comment", "Address" & "Author" in A1, B1 & C1 respectively.
        .Cells(1, 1).Value = "Value"
        .Cells(1, 2).Value = "Cell Address"
    r = 2
        For Each rColored In Sheet9
            .Cells(r, 1).Value = rColored.Value
            .Cells(r, 2).Value = rColored.Parent.Address
            r = r + 1
        Next rColored
        .Columns.AutoFit
End With
End If
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about
VBA Code:
 With Sh
        
        .Cells(1, 1).Resize(, 3).Value = Array("Value", "Cell Address", "Heading")
    r = 2
        For Each rCell In rColored
            .Cells(r, 1).Value = rCell.Value
            .Cells(r, 2).Value = rCell.Address(0, 0)
            .Cells(r, 3).Value = Sheet1.Cells(6, rCell.Column)
            r = r + 1
        Next rCell
        .Columns.AutoFit
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,215,200
Messages
6,123,598
Members
449,109
Latest member
Sebas8956

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