Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 62
Default Follow Up Macro Question

Earlier, I asked about writing a macro to clear the contents of cells whose
value was an alpha dash (-) without changing values or formats of the other
cells. Based on expert feedback, I came up with the following solution.
Highlight the desired range and run the following macro.

Sub ClearDash()
Dim s As String
s = "-"
For Each r in ActiveSheet.UsedRange
If r.Value = s Then
r.ClearContents
End If
Next
End Sub

This works just fine unless a cell in the range contains an error value such
as #N/A in which case the macro aborts at that point with a "Type mismatch"
error. I have been unsuccessful at figuring out a way to skip over any cell
in the range that contains an error value. I thought of maybe using the
following somewhere in the code but I can't get it to work.

If Application.ErrorCheckingOptions.EvaluateToError = True Then

Any ideas on how I can modify the above macro?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Follow Up Macro Question

Hi,

Include this as the first line of your sub routine

On Error Resume Next


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"MrAcquire" wrote:

Earlier, I asked about writing a macro to clear the contents of cells whose
value was an alpha dash (-) without changing values or formats of the other
cells. Based on expert feedback, I came up with the following solution.
Highlight the desired range and run the following macro.

Sub ClearDash()
Dim s As String
s = "-"
For Each r in ActiveSheet.UsedRange
If r.Value = s Then
r.ClearContents
End If
Next
End Sub

This works just fine unless a cell in the range contains an error value such
as #N/A in which case the macro aborts at that point with a "Type mismatch"
error. I have been unsuccessful at figuring out a way to skip over any cell
in the range that contains an error value. I thought of maybe using the
following somewhere in the code but I can't get it to work.

If Application.ErrorCheckingOptions.EvaluateToError = True Then

Any ideas on how I can modify the above macro?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Follow Up Macro Question

You could check for an error:

For Each r in ActiveSheet.UsedRange
if iserror(r.value) then
'skip it???
else
If r.Value = s Then
r.ClearContents
End If
end if
Next r

Or you may be able to test the string you see in the cell:

For Each r in ActiveSheet.UsedRange
If r.Text = s Then
r.ClearContents
End If
Next r

MrAcquire wrote:

Earlier, I asked about writing a macro to clear the contents of cells whose
value was an alpha dash (-) without changing values or formats of the other
cells. Based on expert feedback, I came up with the following solution.
Highlight the desired range and run the following macro.

Sub ClearDash()
Dim s As String
s = "-"
For Each r in ActiveSheet.UsedRange
If r.Value = s Then
r.ClearContents
End If
Next
End Sub

This works just fine unless a cell in the range contains an error value such
as #N/A in which case the macro aborts at that point with a "Type mismatch"
error. I have been unsuccessful at figuring out a way to skip over any cell
in the range that contains an error value. I thought of maybe using the
following somewhere in the code but I can't get it to work.

If Application.ErrorCheckingOptions.EvaluateToError = True Then

Any ideas on how I can modify the above macro?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 62
Default Follow Up Macro Question

I like simple and this solution works perfectly. Thanks for the help, Mike.

"Mike H" wrote:

Hi,

Include this as the first line of your sub routine

On Error Resume Next


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"MrAcquire" wrote:

Earlier, I asked about writing a macro to clear the contents of cells whose
value was an alpha dash (-) without changing values or formats of the other
cells. Based on expert feedback, I came up with the following solution.
Highlight the desired range and run the following macro.

Sub ClearDash()
Dim s As String
s = "-"
For Each r in ActiveSheet.UsedRange
If r.Value = s Then
r.ClearContents
End If
Next
End Sub

This works just fine unless a cell in the range contains an error value such
as #N/A in which case the macro aborts at that point with a "Type mismatch"
error. I have been unsuccessful at figuring out a way to skip over any cell
in the range that contains an error value. I thought of maybe using the
following somewhere in the code but I can't get it to work.

If Application.ErrorCheckingOptions.EvaluateToError = True Then

Any ideas on how I can modify the above macro?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Follow Up Macro Question

You check to see if r has a formula.

Sub ClearDash()
Dim s As String
s = "-"
For Each r In ActiveSheet.UsedRange
If Not r.HasFormula Then
If r.Value = s Then
r.ClearContents
End If
End If
Next
End Sub


Gord Dibben MS Excel MVP

On Thu, 11 Feb 2010 23:18:01 -0800, MrAcquire
wrote:

Earlier, I asked about writing a macro to clear the contents of cells whose
value was an alpha dash (-) without changing values or formats of the other
cells. Based on expert feedback, I came up with the following solution.
Highlight the desired range and run the following macro.

Sub ClearDash()
Dim s As String
s = "-"
For Each r in ActiveSheet.UsedRange
If r.Value = s Then
r.ClearContents
End If
Next
End Sub

This works just fine unless a cell in the range contains an error value such
as #N/A in which case the macro aborts at that point with a "Type mismatch"
error. I have been unsuccessful at figuring out a way to skip over any cell
in the range that contains an error value. I thought of maybe using the
following somewhere in the code but I can't get it to work.

If Application.ErrorCheckingOptions.EvaluateToError = True Then

Any ideas on how I can modify the above macro?


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
Follow up Question to Countif Ajay Excel Discussion (Misc queries) 4 February 16th 09 06:22 PM
A follow up Question Andrew Mackenzie Excel Discussion (Misc queries) 4 November 17th 08 02:50 PM
Follow-up AVERAGEIF question Ken[_3_] New Users to Excel 2 April 11th 08 05:45 PM
Follow-up to Logical Test Question Lance Excel Worksheet Functions 11 March 17th 06 08:14 PM
Follow-Up (Clarification) to MIN question Odawg Excel Discussion (Misc queries) 4 October 20th 05 04:04 AM


All times are GMT +1. The time now is 07:44 AM.

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"