[help] VBA Replace in Text won't finish at the end of text

maulana

New Member
Joined
Sep 16, 2009
Messages
20
Hi,
i want try to change some character in one cell with replace functions in VBA to another cell.

every rows seem ok but at 13th row.
i miss full code. not fully code can't be replace and severed at the end of code.
Code:
Dim p As String
 
 Set a = ActiveWorkbook.Sheets("temp")
 i = 1
 
 While a.Cells(i, 5).Value <> ""
     p = a.Cells(i, 5).Value
     
     p = Replace(p, "+", "|+|", vbTextCompare)
     p = Replace(p, "-", "|-", vbTextCompare)
     p = Replace(p, "(", "|(|", vbTextCompare)
     p = Replace(p, ")", "|)|", vbTextCompare)
     p = Replace(p, "!", "!|", vbTextCompare)
     p = Replace(p, ";", "|;|", vbTextCompare)
     p = Replace(p, "&", "|&|", vbTextCompare)
     p = Replace(p, "||", "|", vbTextCompare)
     a.Cells(i, 6).Value = "'" & p
     i = i + 1
 Wend
 
 
 End Sub
here is my workbooks.
http://www.filehosting.org/<wbr>file/details/160732/max_text.<wbr>xls
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The maximum number of characters in a cell is 32767. Your 13th row result is longer than that so it truncates. To put the remaining characters in the next column, replace:
Code:
     a.Cells(i, 6).Value = "'" & p
with:
Code:
        a.Cells(i, 6).Value = "'" & Left(p, 32766)
        If Len(p) > 32766 Then
            a.Cells(i, 7).Value = "'" & Mid(p, 32767, Len(p))
        End If
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top