Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 04-14-2014, 05:48 PM
excelledsoftware excelledsoftware is offline .Replace does not always work Windows 7 64bit .Replace does not always work Office 2003
IT Specialist
.Replace does not always work
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
.Replace does not always work Multiple replace does not work with 2013 fprm67 Word VBA 11 04-15-2014 03:14 PM
Find and replace No longer work TJH Word 3 03-25-2014 11:33 PM
.Replace does not always work work of labor vs work of excavator ketanco Project 1 02-11-2014 08:53 AM
.Replace does not always work work vs regular work. and how regular work works user0044 Project 5 03-06-2012 07:28 AM
.Replace does not always work Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft