Vba change multiple formulas

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
471
Office Version
  1. 365
Platform
  1. Windows
Hi i have lots of different formulas with range 2 to 77777
Is it possible using a vba to change the 77777 to 177777

example
=COUNTIFS($C$2:$C$77777,C161664) would change to
=COUNTIFS($C$2:$C$177777,C161664)

Thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Use Find & Replace.
Under "Options" select the "Formulas" check box next to "Look in."

The only issue is, I'm not sure whether or not there's a way to prevent cell contents with the "find" value, being replaced, too. What you could do, though, is to use "Find next" to iterate through them all one-by-one, and use "Replace" each time you get to a formula...

Edit - Sorry, didn't notice your "VBA" requirement...
 
Upvote 0
Use Find & Replace.
Under "Options" select the "Formulas" check box next to "Look in."

The only issue is, I'm not sure whether or not there's a way to prevent cell contents with the "find" value, being replaced, too. What you could do, though, is to use "Find next" to iterate through them all one-by-one, and use "Replace" each time you get to a formula...

iv tried using find and replace, but i have that much data on sheet , that it would take around 16 to 24 hours to complete,
I wonder if a vba would be quicker
Thanks
 
Upvote 0
Try this...

NB - test on a COPY of your data, first!!!
VBA Code:
Sub fnd_rep()
Dim cl As Range

Application.ScreenUpdating = False

    On Error Resume Next
 
    For Each cl In Me.UsedRange.SpecialCells(xlFormulas)
        cl.Formula = Replace(cl.Formula, "77777", "177777")
    Next cl

Application.ScreenUpdating = True
End Sub
Edit - missed one of the 7s from the "replace" part!
 
Upvote 0
...It would be quicker to amend the code, to only look at those ranges in which you knew the replacements would be needed - i.e. only certain columns, for example.
 
Upvote 0
Try this...

NB - test on a COPY of your data, first!!!
VBA Code:
Sub fnd_rep()
Dim cl As Range

Application.ScreenUpdating = False

    On Error Resume Next

    For Each cl In Me.UsedRange.SpecialCells(xlFormulas)
        cl.Formula = Replace(cl.Formula, "77777", "177777")
    Next cl

Application.ScreenUpdating = True
End Sub
Edit - missed one of the 7s from the "replace" part!

Thanks for your help
but i get compile error
invalid use of Me keyword
 
Upvote 0
...It would be quicker to amend the code, to only look at those ranges in which you knew the replacements would be needed - i.e. only certain columns, for example.

yes using find and replace i only highlighted the columns that ranges where in, but would still take along time to complete. thanks
 
Upvote 0
...You'll need to place the code in the worksheet module, pertinent to the sheet in question.
Either that, or reference the full sheet name in question, thus:
VBA Code:
Sub fnd_rep()
Dim cl As Range

Application.ScreenUpdating = False

    On Error Resume Next

    For Each cl In Sheets("Sheet1").UsedRange.SpecialCells(xlFormulas)
        cl.Formula = Replace(cl.Formula, "77777", "177777")
    Next cl

Application.ScreenUpdating = True
End Sub
... replace "Sheet1" with the sheet name, in question.
Edit - sorry - missed a double quote off "Sheet1." Corrected now.
 
Upvote 0
VBA Code:
       Sub fnd_rep()
Dim cl As Range

Application.ScreenUpdating = False

On Error Resume Next

For Each cl In Sheets(data).UsedRange.SpecialCells(xlFormulas)
cl.Formula = Replace(cl.Formula, "77777", "177777")
Next cl

Application.ScreenUpdating = True
End Sub

I placed this in module, ran marco, but nothing happened, maybe im missing something
i appreciate your help
 
Upvote 0
...You'll need to place the code in the worksheet module, pertinent to the sheet in question.
Either that, or reference the full sheet name in question, thus:
VBA Code:
Sub fnd_rep()
Dim cl As Range

Application.ScreenUpdating = False

    On Error Resume Next

    For Each cl In Sheets("Sheet1").UsedRange.SpecialCells(xlFormulas)
        cl.Formula = Replace(cl.Formula, "77777", "177777")
    Next cl

Application.ScreenUpdating = True
End Sub
... replace "Sheet1" with the sheet name, in question.
Edit - sorry - missed a double quote off "Sheet1." Corrected now.

Thanks have ran macro, hopefully will work, not sure how long it will take as there is alot of data
thanks again
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top