Forum Discussion
brianrichard1120
May 04, 2021Copper Contributor
PLEASE HELP ENGINEERS
My code has worked for a few months and all of the sudden stopped working. My macro now does find and replace for the whole used range for my data. Here is the code: Sub CleanAC() Dim CharacterA...
brianrichard1120
May 04, 2021Copper Contributor
Disclaimer: This function has been used and operational for 1 month + and has all of the sudden stopped working. Is it something Microsoft did that caused this to stop working. 250+ business owners rely on this function in conjunction with many others to generate reports for themselves.
- HansVogelaarMay 04, 2021MVP
Does this work better?
Sub CleanAC() Dim LastRowPYA As Long Dim CharacterArray As Variant Dim Character As Variant CharacterArray = Array(Chr(58), Chr(92), Chr(47), "~?", "~*", Chr(91), Chr(93)) Application.ScreenUpdating = False With Worksheets("Invoices") LastRowPYA = .Cells(.Rows.Count, "A").End(xlUp).Row With .Range("AB1:AB" & LastRowPYA) .Replace What:=Null, Replacement:="BLANK", LookAt:=xlPart For Each Character In CharacterArray .Replace What:=Character, Replacement:=Chr(32), LookAt:=xlPart Next Character End With End With Application.ScreenUpdating = True End SubAnd perhaps you should change
LastRowPYA = .Cells(.Rows.Count, "A").End(xlUp).Row
to
LastRowPYA = .Cells(.Rows.Count, "AB").End(xlUp).Row
but I cannot judge that.
- brianrichard1120May 04, 2021Copper ContributorThank you for the response. Did you have success running this code here?
Only differences I see are the screen updating and "Next Character."
Any thoughts on why my code has worked well for so long and all the sudden started crashing on various computers on Saturday morning? It was like a switch was flipped and it no longer is valid code.- JMB17May 04, 2021Bronze ContributorThe more obvious difference, to me, is that Hans is not selecting the range. Your issue may be merged cells that are causing the selected range to expand beyond what you are expecting.
If you tested Hans's suggestion and it did not work, then perhaps you could upload a sample workbook with sensitive information removed? But, if you've not tried it yet, you should test his suggestion first.