Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Faster way to find and replace?

I have a single column of IF formulas in a named range ("vbDelete").
If the formula evaluates to -1, then my code will clear the cell. I
repurposed some code I found below. Is there a faster/better way to do
this find/replace? Having a difficult time getting .REPLACE to work
instead----can't get it to work on the formula result. It's finding
the string within the formula and removing it from the formula. Anyway
this is my workaround.
vbDelete contains cells with one formula:

(Column B, vbDelete range)
=IF(A1="SomeValue","Don't Delete", -1)

Sub ClearNegatives()
Dim rngToSearch As Range
Dim rngCurrent As Range
Dim wks As Worksheet
Set wks = ActiveSheet

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set rngToSearch = Range("vbDelete")

For Each rngCurrent In rngToSearch

If rngCurrent.Value = -1 Then _
rngCurrent.ClearContents

Next rngCurrent

Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic

end sub


The above isn't too slow. Just feel like there's a more efficient
approach. Any pointers are appreciated!

PS, this is what I tried to get to work, but it keeps replacing within
the formula and not the formula result:
.Replace what:="DELETE_THIS_CELL", replacement:="", lookat:=xlPart,
searchorder:=xlByRows

"DELETE_THIS_CELL" is replaced by the -1 in ClearNegatives.
The .REPLACE results in:
=IF(A1="SomeValue","Don't Delete", "")

Notice the result is a (changed) formula instead of the cell becoming
blank, which is desired.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Faster way to find and replace?

Sub clearminuscells()
With Columns("b")
.AutoFilter Field:=1, Criteria1:="-1"
.ClearContents
.AutoFilter
End With
End Sub



On Jan 28, 2:43*am, John wrote:
I have a single column of IF formulas in a named range ("vbDelete").
If the formula evaluates to -1, then my code will clear the cell. I
repurposed some code I found below. Is there a faster/better way to do
this find/replace? Having a difficult time getting .REPLACE to work
instead----can't get it to work on the formula result. It's finding
the string within the formula and removing it from the formula. Anyway
this is my workaround.
vbDelete contains cells with one formula:

(Column B, vbDelete range)
=IF(A1="SomeValue","Don't Delete", -1)

Sub ClearNegatives()
* * Dim rngToSearch As Range
* * Dim rngCurrent As Range
* * Dim wks As Worksheet
* * Set wks = ActiveSheet

* * Application.ScreenUpdating = False
* * Application.Calculation = xlCalculationManual

* * Set rngToSearch = Range("vbDelete")

* * For Each rngCurrent In rngToSearch

* * * * If rngCurrent.Value = -1 Then _
* * * * *rngCurrent.ClearContents

* * Next rngCurrent

* * Application.ScreenUpdating = False
* * Application.Calculation = xlCalculationAutomatic

end sub

The above isn't too slow. Just feel like there's a more efficient
approach. Any pointers are appreciated!

PS, this is what I tried to get to work, but it keeps replacing within
the formula and not the formula result:
*.Replace what:="DELETE_THIS_CELL", replacement:="", lookat:=xlPart,
searchorder:=xlByRows

"DELETE_THIS_CELL" is replaced by the -1 in ClearNegatives.
The .REPLACE results in:
=IF(A1="SomeValue","Don't Delete", "")

Notice the result is a (changed) formula instead of the cell becoming
blank, which is desired.


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
FASTER USE OF THE REPLACE() FUNCTION !!!!! jay dean Excel Programming 10 March 27th 10 10:43 PM
Technically, can anyone explain to me why Cells.Find() is so much faster than a loop? Will[_13_] Excel Programming 3 November 6th 07 07:34 PM
Find/Replace Event or Find/Replace for Protected Sheet ... Joe HM Excel Programming 2 October 27th 07 03:55 PM
Faster way to find what part of a range (actually addresses) not intersect with another one? tskogstrom Excel Programming 1 June 17th 07 08:38 AM
Looking for faster way to find minimum value [email protected] Excel Programming 2 July 3rd 06 03:40 PM


All times are GMT +1. The time now is 09:49 PM.

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

About Us

"It's about Microsoft Excel"