[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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,547
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
 

Forum statistics

Threads
1,176,151
Messages
5,901,639
Members
434,909
Latest member
subratgupta

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
Top