Determine if any Cell in Range Equals a String

  • Thread starter Thread starter Connie
  • Start date Start date
C

Connie

I am using the following code to check for errors before appending data
to a sheet in the workbook. I get a data type mismatch for the first
second line:

If Sheets("Error Report").Range("E11:E67") = "Error" Then

How do I check the range E11:E67 on the sheet "Error Report" to
determine if any cell in that range is equal to "Error"?

Private Sub CommandButton4_Click()

'Check for Errors
If Sheets("Error Report").Range("E11:E67") = "Error" Then
MsgBox "You have unresolved ERRORS. Please View Report and
resolve all ERRORS before proceeding."
Exit Sub
Else
'Export Data
ActiveWindow.ScrollWorkbookTabs Sheets:=1
Sheets("Summary Totals").Select
Sheets("Summary Totals").Range("A9:O15").Select
Selection.Copy
Sheets("Compiled Totals").Select
Sheets("Compiled Totals").Range("A9").Select
Do Until ActiveCell.Offset(0, 1).Value = ""
ActiveCell.Offset(1, 0).Range("A1").Select
Loop
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Field Rep Time Sheet").Select
Range("A19").Select
End If
End Sub

Thanks. Connie
 
Connie,
Do you mean exact word "Error" or an error that is generated by Excel, for
whatever reason ?

NickHK
 
Connie
You cannot compare a single value against a range of cells. You could loop
through each cell testing its value, but it's quicker to get Excel to count
them for you:

If Application.CountIf(Sheets(1).Range("E11:E67"), "Error") > 0 Then
MsgBox "You have unresolved ERRORS. Please View Report and resolve all
ERRORS before proceeding."
Exit Sub
End If

NickHK
 
Thanks, Nick. Makes sense. I knew it was something obvious. The code
works. I was testing for the actual value of "Error" (in answer to
your question). Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top