PC Review


Reply
Thread Tools Rate Thread

Determine if any Cell in Range Equals a String

 
 
Connie
Guest
Posts: n/a
 
      10th Oct 2006
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

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      10th Oct 2006
Connie,
Do you mean exact word "Error" or an error that is generated by Excel, for
whatever reason ?

NickHK

"Connie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      10th Oct 2006
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

"Connie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Connie
Guest
Posts: n/a
 
      10th Oct 2006
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.

NickHK wrote:
> 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
>
> "Connie" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine if range has NO Blank Cells without looping through each cell in range Excelenator Microsoft Excel Programming 4 4th Aug 2006 06:30 AM
if cell contains string then make cell next to it equals "X" alex.kemsley@hottubs2buy.co.uk Microsoft Excel Programming 1 21st Jun 2006 06:09 PM
Function to determine if any cell in a range is contained in a given cell choxio@yahoo.com Microsoft Excel Worksheet Functions 3 7th Feb 2005 04:19 PM
shade cell if it equals a word in another cell range =?Utf-8?B?RXZlcmV0?= Microsoft Excel Worksheet Functions 3 12th Aug 2004 08:42 AM
Re: I need to determine a cell range based on a blank cell Katrina Microsoft Excel Programming 1 3rd Jul 2003 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:48 PM.