Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Determine if any Cell in Range Equals a String

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Determine if any Cell in Range Equals a String

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

NickHK

"Connie" wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Determine if any Cell in Range Equals a String

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" wrote in message
oups.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Determine if any Cell in Range Equals a String

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" wrote in message
oups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a cell equals _, at the next row that equals _, return value fr CathyH Excel Worksheet Functions 10 May 2nd 07 07:53 PM
If cell is left blank, or equals zero, then cell equals a different cell John McMurry Excel Discussion (Misc queries) 3 April 13th 07 01:14 PM
Determine if range has NO Blank Cells without looping through each cell in range Excelenator[_29_] Excel Programming 4 August 4th 06 06:30 AM
if cell contains string then make cell next to it equals "X" [email protected] Excel Programming 1 June 21st 06 06:09 PM
if a:a (range) equals january and c:c equals gas then add g:g ($) BCOz Excel Worksheet Functions 4 December 29th 05 07:40 PM


All times are GMT +1. The time now is 04:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"