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
You can drop the WorksheetFunction portion for easier readability:
New_text = Application.Substitute(Cell_reference,"TOTAL","")
- Luciano_LagoCopper Contributorfor me the msg error appeas at the time I am calling F10 key
' RUN_FORREST_RUN Macro
'
'
ChDir "Y:\Luciano"
ActiveWorkbook.SaveAs Filename:= _
"Y:\Luciano\Segment Report Conso Excel Link.xlsb", FileFormat:=xlExcel12, _
CreateBackup:=False
Sheets("CoA").Select
Range("CoA[[#Headers],[ACCOUNT NUMBER]]").Select
Application.Run Range("cc.F10")
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False - Man Fai ChanIron Contributor
I suspect the LastRow - 1 gives zero or negative number.
- Lorenzo KimBronze Contributor
Mr. Chan
Here I am again, pardon for the bother..
kindly help with the small snippet below
I wish to erase in a range of column the word "Total" in a cell.
in EXCEL it is =left(cellText, len(cellText)-5)
How do I write it in vba?
many 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
' remove the word total inside a column range cell
Next i
Application.ScreenUpdating = True
End Sub
- Man Fai ChanIron Contributor
Dear Kim,
I heard a worksheet function: "SUBSTITUTE" which can perform your task:
SUBSTITUE(A1,"TOTAL","")Cheers
Chan M F
- Lorenzo KimBronze Contributor
Mr Chan
I think it is -- the lastrow was 0!
Thank you for your reply...
- Haytham AmairahSilver Contributor
Hi Lorenzo,
The Cells function requires two arguments: RowIndex & ColumnIndex
Both must be a number, not a text!
You put the text "C" in the ColumnIndex, so try to replace it with 3 instead.
Regards
- Lorenzo KimBronze ContributorMr. Amairah
Thank you for your time...- Matt MickleBronze Contributor
This is a good example of when it pays to debug the code using F8. You can step through the code one line at a time and then hover over the variable in order to get it's value.....or you van use a watch which you can see in the immediate window or perhaps even type in a statement into the immediate window....
This will save you a ton of time in the long run....
Watch Window
https://www.youtube.com/watch?v=19JTjCtFPeI
Immediate Window