Forum Discussion
Lorenzo Kim
Jul 14, 2018Bronze Contributor
runtime error 1004 : Method range of object - 'Global' failed
How do I correct this? (kindly see images) many many thanks
- Jul 17, 2018
You can drop the WorksheetFunction portion for easier readability:
New_text = Application.Substitute(Cell_reference,"TOTAL","")
Man Fai Chan
Jul 15, 2018Iron Contributor
Dear Kim,
The statement is as follows:
New_text = Application.WorksheetFunction.Substitute(Cell_reference,"TOTAL","")
Cheers,
Chan M F
Matt Mickle
Jul 17, 2018Bronze Contributor
You can drop the WorksheetFunction portion for easier readability:
New_text = Application.Substitute(Cell_reference,"TOTAL","")
- Lorenzo KimJul 17, 2018Bronze Contributor
Mr. Mickle
Thank you for the new tip. A new horizon....
the final SUB would be below. ( It worked nicely )
(it is case sensitive)
many many thanks
Sub RemoveWordTotal()
Application.ScreenUpdating = False
Dim i As Long
For i = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
Cells(i, "B") = Application.Substitute(Cells(i, "B"),"Total","")
Next i
Application.ScreenUpdating = True
End Sub
The above can also be used to replace a text instead of just blank.
instead of "" - replace it with "New Text" !!
VERY VERSATILE CODE, Mr. Mickle..
FOR OTHERS WHO MIGHT FIND THIS USEFUL:
maybe called as function (BELOW) > Call ReplaceSomeText("Total", "B", "")
"Total" (mWRD) = the word within the cell to be replaced
"B" (mcol) = the column referenced
"" (newTXT) = blank or any text to replace mWRD
Sub ReplaceSomeText(mWRD As String, mcol As String, newTXT As String)
Application.ScreenUpdating = False
Dim i As Long
For i = Cells(Rows.Count, mcol).End(xlUp).Row To 2 Step -1
Cells(i, mcol) = Application.Substitute(Cells(i, mcol),mWRD, newTXT)
Next i
Application.ScreenUpdating = True
End Sub- Lorenzo KimJul 17, 2018Bronze Contributor
Mr. Chan
All along you are suggesting what Mr. Mickle had just recommended..
sorry If I didn't "see" it earlier.
many many thanks