Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Macro Error When It Can't Find Value

I am using the following code to move the negative sign from the back of a
number to the front of the number:
For Each cell In Selection.SpecialCells(xlConstants, xlTextValues)
s = Trim(cell)
If IsNumeric(s) Then
cell.Value = CDbl(s)
End If
Next
This code works when there is a negative in the column. However, it does
not work when it can't find a negative. It gives me a "Run-time error
'1004': No cells were found".
Does anyone know how to code this so that the macro keeps going and dosn't
error out?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Macro Error When It Can't Find Value

Give this a try...

dim rngToConvert as range

on error resume next
set rngToConvert = Selection.SpecialCells(xlConstants, xlTextValues)
on error goto 0

if not rngtoconvert is nothing then
For Each cell In rngToConvert
s = Trim(cell)
If IsNumeric(s) Then
cell.Value = CDbl(s)
End If
Next
end if
--
HTH...

Jim Thomlinson


"tedd13" wrote:

I am using the following code to move the negative sign from the back of a
number to the front of the number:
For Each cell In Selection.SpecialCells(xlConstants, xlTextValues)
s = Trim(cell)
If IsNumeric(s) Then
cell.Value = CDbl(s)
End If
Next
This code works when there is a negative in the column. However, it does
not work when it can't find a negative. It gives me a "Run-time error
'1004': No cells were found".
Does anyone know how to code this so that the macro keeps going and dosn't
error out?
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Macro Error When It Can't Find Value

If all else fails "On Error Resume Next"
Be sure to place "On Error Goto 0"
after the error-prone lines.
--
Best wishes,

Jim


"tedd13" wrote:

I am using the following code to move the negative sign from the back of a
number to the front of the number:
For Each cell In Selection.SpecialCells(xlConstants, xlTextValues)
s = Trim(cell)
If IsNumeric(s) Then
cell.Value = CDbl(s)
End If
Next
This code works when there is a negative in the column. However, it does
not work when it can't find a negative. It gives me a "Run-time error
'1004': No cells were found".
Does anyone know how to code this so that the macro keeps going and dosn't
error out?
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Macro Error When It Can't Find Value

Take a look he

http://mcgimpsey.com/excel/postfixnegatives.html

In article ,
tedd13 wrote:

I am using the following code to move the negative sign from the back of a
number to the front of the number:
For Each cell In Selection.SpecialCells(xlConstants, xlTextValues)
s = Trim(cell)
If IsNumeric(s) Then
cell.Value = CDbl(s)
End If
Next
This code works when there is a negative in the column. However, it does
not work when it can't find a negative. It gives me a "Run-time error
'1004': No cells were found".
Does anyone know how to code this so that the macro keeps going and dosn't
error out?
Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Error When It Can't Find Value

On Mar 30, 8:43 am, JE McGimpsey wrote:
Take a look he

http://mcgimpsey.com/excel/postfixnegatives.html

In article ,



tedd13 wrote:
I am using the following code to move the negative sign from the back of a
number to the front of the number:
For Each cell In Selection.SpecialCells(xlConstants, xlTextValues)
s = Trim(cell)
If IsNumeric(s) Then
cell.Value = CDbl(s)
End If
Next
This code works when there is a negative in the column. However, it does
not work when it can't find a negative. It gives me a "Run-time error
'1004': No cells were found".
Does anyone know how to code this so that the macro keeps going and dosn't
error out?
Thanks- Hide quoted text -


- Show quoted text -


All you have to do to get your code to work is change
SpecialCells(xlConstants, xlTextValues) to SpecialCells(xlConstants)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Macro Error When It Can't Find Value

Not really. Using .SpecialCells(xlConstants) will still throw an error
if there are no constants in the range.

In article .com,
"Paul" wrote:

All you have to do to get your code to work is change
SpecialCells(xlConstants, xlTextValues) to SpecialCells(xlConstants)

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
Find Macro Error StillLearning Excel Discussion (Misc queries) 5 December 11th 09 06:58 PM
change error message when no more for "find" in macro to find swyltm Excel Programming 1 January 13th 06 05:16 PM
ERROR 91 with FIND in macro Robert AS Excel Programming 5 January 21st 05 12:48 PM
can't find error in macro logic... tehwa[_6_] Excel Programming 7 January 15th 04 06:27 AM
macro error "can't find project or library" Meinfs Excel Programming 3 September 14th 03 04:29 PM


All times are GMT +1. The time now is 07:27 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"