PLEASE HELP ENGINEERS

%3CLINGO-SUB%20id%3D%22lingo-sub-2323798%22%20slang%3D%22en-US%22%3EPLEASE%20HELP%20ENGINEERS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323798%22%20slang%3D%22en-US%22%3E%3CP%3EMy%20code%20has%20worked%20for%20a%20few%20months%20and%20all%20of%20the%20sudden%20stopped%20working.%20My%20macro%20now%20does%20find%20and%20replace%20for%20the%20whole%20used%20range%20for%20my%20data.%20Here%20is%20the%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20CleanAC()%3C%2FP%3E%3CP%3EDim%20CharacterArray%20As%20Variant%3C%2FP%3E%3CP%3ECharacterArray%20%3D%20Array(Chr(58)%2C%20Chr(92)%2C%20Chr(47)%2C%20%22~%3F%22%2C%20%22~*%22%2C%20Chr(91)%2C%20Chr(93))%3C%2FP%3E%3CP%3EDim%20Character%20As%20Variant%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESheets(%22Invoices%22).Activate%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20Sheets(%22Invoices%22)%3C%2FP%3E%3CP%3ELastRowPYA%20%3D%20Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row%3C%2FP%3E%3CP%3ERange(%22AB1%3AAB%22%20%26amp%3B%20LastRowPYA).Select%3C%2FP%3E%3CP%3EWith%20Selection%3C%2FP%3E%3CP%3E.Replace%20What%3A%3DNull%2C%20Replacement%3A%3D%22BLANK%22%2C%20LookAt%3A%3DxlPart%3C%2FP%3E%3CP%3EFor%20Each%20Character%20In%20CharacterArray%3C%2FP%3E%3CP%3E.Replace%20What%3A%3DCharacter%2C%20Replacement%3A%3DChr(32)%2C%20LookAt%3A%3DxlPart%3C%2FP%3E%3CP%3ENext%3C%2FP%3E%3CP%3EEnd%20With%3C%2FP%3E%3CP%3EEnd%20With%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20should%20only%20be%20looking%20at%20column%20AB%20and%20it%20does%20find%20and%20replace%20on%20the%20whole%20worksheets%20used%20range!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2323798%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2323833%22%20slang%3D%22en-US%22%3ERE%3A%20PLEASE%20HELP%20ENGINEERS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323833%22%20slang%3D%22en-US%22%3EDisclaimer%3A%20This%20function%20has%20been%20used%20and%20operational%20for%201%20month%20%2B%20and%20has%20all%20of%20the%20sudden%20stopped%20working.%20Is%20it%20something%20Microsoft%20did%20that%20caused%20this%20to%20stop%20working.%20250%2B%20business%20owners%20rely%20on%20this%20function%20in%20conjunction%20with%20many%20others%20to%20generate%20reports%20for%20themselves.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2323857%22%20slang%3D%22en-US%22%3ERE%3A%20PLEASE%20HELP%20ENGINEERS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323857%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1045126%22%20target%3D%22_blank%22%3E%40brianrichard1120%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDoes%20this%20work%20better%3F%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20CleanAC()%0A%20%20%20%20Dim%20LastRowPYA%20As%20Long%0A%20%20%20%20Dim%20CharacterArray%20As%20Variant%0A%20%20%20%20Dim%20Character%20As%20Variant%0A%20%20%20%20CharacterArray%20%3D%20Array(Chr(58)%2C%20Chr(92)%2C%20Chr(47)%2C%20%22~%3F%22%2C%20%22~*%22%2C%20Chr(91)%2C%20Chr(93))%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20With%20Worksheets(%22Invoices%22)%0A%20%20%20%20%20%20%20%20LastRowPYA%20%3D%20.Cells(.Rows.Count%2C%20%22A%22).End(xlUp).Row%0A%20%20%20%20%20%20%20%20With%20.Range(%22AB1%3AAB%22%20%26amp%3B%20LastRowPYA)%0A%20%20%20%20%20%20%20%20%20%20%20.Replace%20What%3A%3DNull%2C%20Replacement%3A%3D%22BLANK%22%2C%20LookAt%3A%3DxlPart%0A%20%20%20%20%20%20%20%20%20%20%20For%20Each%20Character%20In%20CharacterArray%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Replace%20What%3A%3DCharacter%2C%20Replacement%3A%3DChr(32)%2C%20LookAt%3A%3DxlPart%0A%20%20%20%20%20%20%20%20%20%20%20Next%20Character%0A%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20End%20With%0A%20%20%20%20Application.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAnd%20perhaps%20you%20should%20change%3C%2FP%3E%0A%3CP%3ELastRowPYA%20%3D%20.Cells(.Rows.Count%2C%20%22A%22).End(xlUp).Row%3C%2FP%3E%0A%3CP%3Eto%3C%2FP%3E%0A%3CP%3ELastRowPYA%20%3D%20.Cells(.Rows.Count%2C%20%22AB%22).End(xlUp).Row%3C%2FP%3E%0A%3CP%3Ebut%20I%20cannot%20judge%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2323936%22%20slang%3D%22en-US%22%3ERE%3A%20PLEASE%20HELP%20ENGINEERS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323936%22%20slang%3D%22en-US%22%3EThank%20you%20for%20the%20response.%20Did%20you%20have%20success%20running%20this%20code%20here%3F%3CBR%20%2F%3EOnly%20differences%20I%20see%20are%20the%20screen%20updating%20and%20%22Next%20Character.%22%3CBR%20%2F%3E%3CBR%20%2F%3EAny%20thoughts%20on%20why%20my%20code%20has%20worked%20well%20for%20so%20long%20and%20all%20the%20sudden%20started%20crashing%20on%20various%20computers%20on%20Saturday%20morning%3F%20It%20was%20like%20a%20switch%20was%20flipped%20and%20it%20no%20longer%20is%20valid%20code.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2323989%22%20slang%3D%22en-US%22%3ERE%3A%20PLEASE%20HELP%20ENGINEERS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323989%22%20slang%3D%22en-US%22%3EI%20wonder%20if%202105%20will%20fix%20this.%20I%20sure%20hope%20so!%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fofficeupdates%2Fcurrent-channel-preview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fofficeupdates%2Fcurrent-channel-preview%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2324056%22%20slang%3D%22en-US%22%3ERE%3A%20PLEASE%20HELP%20ENGINEERS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2324056%22%20slang%3D%22en-US%22%3EThe%20more%20obvious%20difference%2C%20to%20me%2C%20is%20that%20Hans%20is%20not%20selecting%20the%20range.%20Your%20issue%20may%20be%20merged%20cells%20that%20are%20causing%20the%20selected%20range%20to%20expand%20beyond%20what%20you%20are%20expecting.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20tested%20Hans's%20suggestion%20and%20it%20did%20not%20work%2C%20then%20perhaps%20you%20could%20upload%20a%20sample%20workbook%20with%20sensitive%20information%20removed%3F%20But%2C%20if%20you've%20not%20tried%20it%20yet%2C%20you%20should%20test%20his%20suggestion%20first.%3C%2FLINGO-BODY%3E
Occasional Contributor

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 CharacterArray As Variant

CharacterArray = Array(Chr(58), Chr(92), Chr(47), "~?", "~*", Chr(91), Chr(93))

Dim Character As Variant

 

Sheets("Invoices").Activate

 

With Sheets("Invoices")

LastRowPYA = Cells(Rows.Count, "A").End(xlUp).Row

Range("AB1:AB" & LastRowPYA).Select

With Selection

.Replace What:=Null, Replacement:="BLANK", LookAt:=xlPart

For Each Character In CharacterArray

.Replace What:=Character, Replacement:=Chr(32), LookAt:=xlPart

Next

End With

End With

End Sub

 

This should only be looking at column AB and it does find and replace on the whole worksheets used range!

14 Replies
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.

@brianrichard1120 

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.

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.
I wonder if 2105 will fix this. I sure hope so! https://docs.microsoft.com/en-us/officeupdates/current-channel-preview
The 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.
Thank 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.

@brianrichard1120 I figured out how to post this @JMB17 @Hans Vogelaar and anyone willing to help. 

Looking at this I understand my find and replace was only supposed to work on column L. You can change it to one of the first few columns there to work. But either way the error is still evident.
It does not appear that the sample data contains any of the characters the macro is looking for?

I added some of the characters to be replaced to the data in columns A-E and added some data containing the characters to be replaced in column L. It does not appear that I'm able to replicate the problem - the macro found and replaced the specified characters in Column L without bothering any of the other data.

By chance, do you have any other vba code that may be interfering, such as a worksheet_change event handler (or some other event handler) that may be getting triggered by the find/replace action?

I truly appreciate your continued attention to this issue here. I have no other interference. Sometimes the sheet does not contain those characters, but when it does I need to address it so that’s why it’s in there. My main concern is to fill in the blank values in the specific column that I specify. Would you mind changing the column of attention to column b in the sheet test and running the code? Theoretically it should just fill in the blank cells in column b with the word BLANK. (My mistake at having it look at column l) just to explain what mine is doing when I run it... it is filling in every blank cell in the used range within the whole workbook with the word BLANK

@JMB17 I am running 2104 btw.

@brianrichard1120 

 

Yes, changing the code to look at column b:

 

Sub CleanAC()

    Dim CharacterArray As Variant
    CharacterArray = Array(Chr(58), Chr(92), Chr(47), "~?", "~*", Chr(91), Chr(93))
    Dim Character As Variant
    
    Sheets("Test").Activate
    With Sheets("Test")
        LastRowPYA = Cells(Rows.Count, "A").End(xlUp).Row
        With Range("B1:B" & 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

End Sub

 

 

results in this:

 

JMB17_1-1620174060068.png

 

But, I'm working on office 2016. 

 

As a side note, there would usually be a period before "cells", "rows", and "range" to tell vba you are referring to the object in the "with" statement. In this specific case, it shouldn't matter because you are activating  the "test" worksheet first and unqualified references will refer to the active sheet. But, if the activate statement were removed, then the object references would be a mixture between the "test" worksheet and whatever the active sheet was.

 

LastRowPYA = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Range("B1:B" & LastRowPYA)

 

Understood. I appreciate that explanation regarding the . And active sheets. I am convinced that something in excel has broke causing this error. I do hope that other readers will run my test file I posted and hopefully replicate my error. I will post what mine looks like when I have a chance tomorrow. Wish it produced the same results as yours :(.
I have brought this to the attention of Microsoft support yesterday and earlier today and they shrugged me off. That’s why I have resorted to this community to help and also hope that a Microsoft employee sees these posts.