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.
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.
- refer to sheet sheet "Test Data Request" rather than run in current sheet
- Ignore rows 1 and 2 and only check rows 3 and below.
- specify columns to check.
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