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...
HansVogelaar
May 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 Sub
And 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.
brianrichard1120
May 04, 2021Copper Contributor
Thank 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.
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.- brianrichard1120May 04, 2021Copper ContributorThank you for your response and pointing out that difference. I just attempted Hans solution and was met with the same problem unfortunately. My data varies in size but I am doing testing on a simple data set. I will post once I figure out how.
- brianrichard1120May 04, 2021Copper Contributor
brianrichard1120 I figured out how to post this JMB17 HansVogelaar and anyone willing to help.
- brianrichard1120May 04, 2021Copper ContributorI wonder if 2105 will fix this. I sure hope so! https://docs.microsoft.com/en-us/officeupdates/current-channel-preview