LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Selection.Replace size limitation

Thanks very much Dave, it worked a treat.

--
http://www.takesyourfancy.co.uk/ - Great products and great prices for all
the family

I think you have to work around it.

Option Explicit
Sub testme01()

Dim FoundCell As Range
Dim ConstCells As Range
Dim BeforeStr As String
Dim AfterStr As String

BeforeStr = vblf
AfterStr = " "

With ActiveSheet
Set ConstCells = Nothing
On Error Resume Next
Set ConstCells = .Cells.SpecialCells(xlCellTypeConstants, _
xlTextValues)
On Error GoTo 0

If ConstCells Is Nothing Then
MsgBox "Select some cells in the used range"
Exit Sub
End If

With ConstCells
'get as many as we can in one step
.Replace what:=BeforeStr, Replacement:=AfterStr, _
lookat:=xlPart, SearchOrder:=xlByRows

Do
Set FoundCell = .Cells.Find(what:=BeforeStr, _
after:=.Cells(1), _
LookIn:=xlValues, _
lookat:=xlPart, _
SearchOrder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
'done, get out!
Exit Do
End If
FoundCell.Value _
= Replace(FoundCell.Value, BeforeStr, AfterStr)
Loop
End With
End With
End Sub

If you're using xl97, change that Replace() to application.substitute()

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ps. Try it against a copy of your data--just in case!

Stopfordian wrote:

I have Excel 2002, SP-2.

If the text cell selected is big in length, the code below does not work.

Sub Trim10()
Dim cell As Range
Selection.Replace What:=Chr(10), replacement:=Chr(32), _
lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
End Sub

The longest length which worked was 945 but some which are less than that
also did not work for some reason. Under 900 and it looks as thought it
always works. I can confirm that the ones which haven't worked do
contain
Chr(10).
Is there anything I can do to fix this size limitation?

Thanks
--
http://www.takesyourfancy.co.uk/ - Great products and great prices for
all
the family


--

Dave Peterson



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel file size limitation Stew_Katz Excel Discussion (Misc queries) 5 April 10th 10 07:45 AM
Autofilter - 1000 Selection Limitation? JohnG Excel Discussion (Misc queries) 1 April 28th 09 03:16 AM
Userform size limitation Michael Harrer Excel Programming 0 July 9th 04 12:48 PM
Array size limitation? QuocAnh Excel Programming 9 November 21st 03 11:34 PM
SheetSelectionChange Target size Limitation? Guillaume E. Excel Programming 1 September 27th 03 04:34 PM


All times are GMT +1. The time now is 09:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"