Providing message if red coloured cells found in specific columns

djdbg1

New Member
Joined
Aug 23, 2017
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I have a worksheet, "Test Data Request" which has numerous data validations. I have had to enable this worksheet to allow "paste as link" to work as some business areas will be pasting in data from a source system extract rather than manually populating each field. As this will overwrite the data validations, i have used conditional formatting to change a cell to red fill if it doesn't match one of the data validation options.
In case the red cells are not seen, i want to add a button that would confirm if everything in that worksheet ("Test Data Request"), from rows 3 and below was good, i.e. no red cells or if "Invalid Data or Required Data Missing - Please fix before proceeding".
The script below looks for red cells by referencing $A$2 (as it will always be red as its a mandatory header i have filled red).
However i want to have this button on a different worksheet. I can't figure out where to reference worksheet "Test Data Request" and where to define range is ROW3 and above.
Finally not all cells are mandatory. Some may appear red as blank, but they are optional, so i also need to confirm which columns to check. I would really appreciate of anyone could offer suggestion how to get the below script to do as i need.
  1. refer to sheet sheet "Test Data Request" rather than run in current sheet
  2. Ignore rows 1 and 2 and only check rows 3 and below.
  3. specify columns to check.
TIA

VBA Code:
Sub SumCountByConditionalFormat()
    Dim indRefColor As Long
    Dim cellsColorSample As Range
    Dim cntRes As Long
    Dim sumRes
    Dim cntCells As Long
    Dim indCurCell As Long

    On Error Resume Next

    cntRes = 0
    sumRes = 0

    cntCells = Selection.CountLarge

    Set cellsColorSample = Range("$A$2")

    If Not (cellsColorSample Is Nothing) Then
       indRefColor = cellsColorSample.Cells(1, 1).DisplayFormat.Interior.Color

       For indCurCell = 1 To (cntCells)
            If indRefColor = Selection(indCurCell).DisplayFormat.Interior.Color Then
               cntRes = cntRes + 1
               sumRes = WorksheetFunction.Sum(Selection(indCurCell), sumRes)
            End If
        Next
        MsgBox "Invalid Data or Required Data Missing - Please fix before proceeding"
    End If
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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