Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substitute Function in Excel VBA for cell range

I have to replace one character with another in Excel file.

I have used following Replace function, but due to exceeds of 1024 character limit in some cells, it stops there.

Sub Replace()

    With Sheets("Sheet1").Range("A1:A629")   

      .Cells.Replace ",", ";", xlPart, xlByRows, False

    End With

End Sub 

I got to know Substitute function would do

Cells(1, 2) = "=SUBSTITUTE(A1,"","","";"")"

But how do I use that for cell range?

like image 640
SMPH Avatar asked Jul 10 '13 01:07

SMPH


1 Answers

Try this

Sub Replace()

    Dim rng As Range, cell As Range
    Set rng = Sheets("Sheet1").Range("A1:A629")

    For Each cell In rng
        cell = WorksheetFunction.Substitute(cell, ",", ";")
    Next
End Sub

enter image description here

like image 184
Santosh Avatar answered Sep 18 '22 23:09

Santosh