[VBA] Activecell.replace is now replacing the contents of my entire workbook.

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
810
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

Have the below code

VBA Code:
ActiveCell.Replace What:=", ", Replacement:=",", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

This has been working perfectly for half a year now, but all of a sudden it appears to be replacing the contents of cell B2.

In summary, I have a list of pickups separated as follows: "Worcester, Bromsgrove, Redditch, Tewkesbury"

This is then copied from B2 to B6, and in the copied list in B6 it's altered to: "Worcester,Bromsgrove,Redditch,Tewkesbury"

For some reason, even though the active cell is clearly B6, it is changing it not only in B2, but also, in every other cell on other sheets too!


Even if I change it to be "range("B6").replace" - it still happens???
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Put this just before that line
VBA Code:
Range("A1").Find "*"
 
Upvote 0
Put this just before that line
VBA Code:
Range("A1").Find "*"
Could you explain what that does?

And how is it that I haven't made any changes to this weekly ran file and all of a sudden such a critical error is occurring? Thank you!
 
Upvote 0
It sounds as though somebody has done a manual search/replace & change the "within" option from Sheet to Workbook.
That code simply resets it back to Sheet
 
Upvote 0
Ah, that's very irritating, that person would be me, but on another sheet. It's been pretty catastrophic!
 
Upvote 0
There really isn't any benefit to using Range.Replace when Range is just one cell. You're better off using the Replace function and assigning the result to the cell formula property.
 
Upvote 0
There really isn't any benefit to using Range.Replace when Range is just one cell. You're better off using the Replace function and assigning the result to the cell formula property.

Yeah you're right, I should amend.

Liking the new photo :'D
 
Upvote 0
What can I say, I'm a good boy. :)
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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