View Single Post
 
Old 04-14-2014, 05:48 PM
excelledsoftware excelledsoftware is offline Windows 7 64bit Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Here is an update on this problem. I tried setting the parameters and it still did not work. I actually forgot something very important when it comes to .replace. The reason it only works half the time is due to the length of the string. If the string is over 912 characters it simply will not work. I will be modifying my current code to store the string in separate variables of 900 characters. I wrote a simple code below to prove this theory. Thanks everyone for their help.
Code:
Option Explicit
Sub ReplaceTest()
    ' checks to see what limit a .replace can handle.
    Dim CheckAmount As Integer
    Dim Success As Boolean
    CheckAmount = 2000
    Success = False
    Do Until Success = True
        Range("a1").Value = WorksheetFunction.Rept("x", CheckAmount)
        Range("a1").Replace "x", "s"
        If Left(Range("a1").Value, 1) = "s" Then
            Success = True
            Exit Do
        End If
        CheckAmount = CheckAmount - 1
    Loop
    
    Range("B1").Value = CheckAmount + 1 ' Add one since the loop took one away.
    MsgBox "The replace works with " & CheckAmount + 1 & " characters max."
       
        
End Sub
Reply With Quote