Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Correcting #NAME errors

Hi

I have a small piece of code that appears to work fine on
small files but when the code is applied to a large file
with a very large number of #NAME errors it "hangs".The VB
code snippet is produced below. (The #NAME errors arise in
a CSV file where the first character in a text field is
a "-").

Please can someone shed some light on this peculiarity?

THANKS

Tim



Dim rTemp As Range

Set rTemp = Cells.Find(What:="#Name?", After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False)
Do While Not rTemp Is Nothing
'Application.ScreenUpdating = False
If Not rTemp Is Nothing Then
With rTemp
.Value = Chr(39) & Mid(.Formula, 2, Len
(.Formula) - 1)
End With
End If
Set rTemp = Cells.Find(What:="#Name?",
After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False)
Loop
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Correcting #NAME errors

I think that excel sees that dash as a minus and figures you're writing a
formula.

You could rename your .csv file to .txt and then import and really specify Text
for that field (and you won't have the trouble).

Or you could look for the errors like you're doing.

Or this worked for me in light testing.
Select all the cells
edit|goto|special
formulas & errors only.
Edit|replace
=-
with
'-

As a macro:

Option Explicit
Sub testme01()

Dim myErrRng As Range

Set myErrRng = Nothing
On Error Resume Next
Set myErrRng = ActiveSheet.UsedRange _
.Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
On Error GoTo 0
If myErrRng Is Nothing Then
'do nothing
Else
myErrRng.Replace What:="=-", Replacement:="'-", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End If
End Sub

======
I think if I were doing it, I'd do the .txt stuff. I think having more control
is better.

===
But I ran your code (with a minor change near the bottom:
Set rTemp = Cells.FindNext(rTemp)
instead of the .find you used again)

And it worked ok with about 27000 cells that needed fixing--it didn't hang up at
all.




Tim Childs wrote:

Hi

I have a small piece of code that appears to work fine on
small files but when the code is applied to a large file
with a very large number of #NAME errors it "hangs".The VB
code snippet is produced below. (The #NAME errors arise in
a CSV file where the first character in a text field is
a "-").

Please can someone shed some light on this peculiarity?

THANKS

Tim

Dim rTemp As Range

Set rTemp = Cells.Find(What:="#Name?", After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False)
Do While Not rTemp Is Nothing
'Application.ScreenUpdating = False
If Not rTemp Is Nothing Then
With rTemp
.Value = Chr(39) & Mid(.Formula, 2, Len
(.Formula) - 1)
End With
End If
Set rTemp = Cells.Find(What:="#Name?",
After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False)
Loop


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Correcting #NAME errors

Dave

Thanks for your help on this. It is much appreciated.

The proc you sent worked real fast but I need to double
check that it would not have any "false positives" or
uninended consequences.

That final tip about using Find Next seems to have done
the trick on some initial testing on a large file.

Unfortunately, I do not have the "luxury" of going down
the TXT route as the VB is part of a larger formatting
routine used by people who are not comfortable renaming
files (and it would be slow).

Thanks again

Tim



-----Original Message-----
I think that excel sees that dash as a minus and figures

you're writing a
formula.

You could rename your .csv file to .txt and then import

and really specify Text
for that field (and you won't have the trouble).

Or you could look for the errors like you're doing.

Or this worked for me in light testing.
Select all the cells
edit|goto|special
formulas & errors only.
Edit|replace
=-
with
'-

As a macro:

Option Explicit
Sub testme01()

Dim myErrRng As Range

Set myErrRng = Nothing
On Error Resume Next
Set myErrRng = ActiveSheet.UsedRange _
.Cells.SpecialCells

(xlCellTypeFormulas, xlErrors)
On Error GoTo 0
If myErrRng Is Nothing Then
'do nothing
Else
myErrRng.Replace What:="=-", Replacement:="'-",

LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End If
End Sub

======
I think if I were doing it, I'd do the .txt stuff. I

think having more control
is better.

===
But I ran your code (with a minor change near the bottom:
Set rTemp = Cells.FindNext(rTemp)
instead of the .find you used again)

And it worked ok with about 27000 cells that needed

fixing--it didn't hang up at
all.




Tim Childs wrote:

Hi

I have a small piece of code that appears to work fine

on
small files but when the code is applied to a large file
with a very large number of #NAME errors it "hangs".The

VB
code snippet is produced below. (The #NAME errors arise

in
a CSV file where the first character in a text field is
a "-").

Please can someone shed some light on this peculiarity?

THANKS

Tim

Dim rTemp As Range

Set rTemp = Cells.Find(What:="#Name?",

After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False)
Do While Not rTemp Is Nothing
'Application.ScreenUpdating = False
If Not rTemp Is Nothing Then
With rTemp
.Value = Chr(39) & Mid(.Formula, 2, Len
(.Formula) - 1)
End With
End If
Set rTemp = Cells.Find(What:="#Name?",
After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:= _
False)
Loop


--

Dave Peterson

.

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
Correcting Multiple Div#0s ANTBOH Excel Worksheet Functions 6 January 19th 10 08:39 PM
Help with correcting writing a formula tuk16664 Excel Worksheet Functions 5 February 6th 07 01:13 PM
Correcting an extrapolation macro smurray444 Excel Discussion (Misc queries) 2 February 1st 06 10:29 AM
Correcting a #REF! David Hauck Excel Worksheet Functions 1 December 20th 05 05:16 PM
need help in correcting the formula azmi Excel Worksheet Functions 1 June 11th 05 08:36 PM


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