I have a replace function in a MACRo that works but would like to use Substitute. Can someone review and update to use Substitute?

BudZ 121 Reputation points

Range(Cells(2, 11), Cells(lastRow, lastCol)).Select ' Starting in row 2 and starting 11 rows over the H will be removed in any columns and rows after that through the end of those columns and rows
tmpErr = Err.Number
On Error Resume Next
Selection.Replace What:="h", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
tmpErr = Err.Number
On Error GoTo 0

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,570 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 18,765 Reputation points

    Did you try this method?

    Dim cell As Range
    For Each cell In Range(Cells(2, 11), Cells(lastRow, lastCol))
        cell.Value = Application.WorksheetFunction.Substitute(cell.Value, "h", "")
    Next cell
    0 comments No comments