Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Designating Sheet vs Workbook When Doing Find/Replace

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Designating Sheet vs Workbook When Doing Find/Replace

What's the intent of this line?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select

I'm guessing that's part of the problem.
--
HTH,
Barb Reinhardt



"Paige" wrote:

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Designating Sheet vs Workbook When Doing Find/Replace

It's suppose to tell it what range to do the find/replace.

"Barb Reinhardt" wrote:

What's the intent of this line?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select

I'm guessing that's part of the problem.
--
HTH,
Barb Reinhardt



"Paige" wrote:

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Designating Sheet vs Workbook When Doing Find/Replace

Is the range from G3 to the last row of data in G?

This may not be the most elegant, but it works

Sub Test()
Dim myWS As Worksheet
Dim myRange As Range
Dim r As Range
Dim lRow As Long

Set myWS = Worksheets("MMS for CP")
lRow = myWS.Cells(myWS.Rows.Count, "G").End(xlUp).Row
Set myRange = myWS.Range("G3").Resize(lRow - 3 + 1, 1)

For Each r In myRange
r.Value = Replace(r.Value, " ", "")
Next r

End Sub

--
HTH,
Barb Reinhardt



"Paige" wrote:

It's suppose to tell it what range to do the find/replace.

"Barb Reinhardt" wrote:

What's the intent of this line?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select

I'm guessing that's part of the problem.
--
HTH,
Barb Reinhardt



"Paige" wrote:

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Designating Sheet vs Workbook When Doing Find/Replace

Hi, Barb. The range is from G3 to the last row of data in G. I'm trying not
to use the "for each....next" method because there are so many rows and it
adds too much processing time. That's why I was trying to do Find/Replace,
but can't seem to tell it to make sure and only do that within the specified
range and not within the entire workbook. If you go to Edit | Replace in
Excel, the Find and Replace dialog box gives you an option to do this within
workbook or sheet, but I don't know how to do it with code.

"Barb Reinhardt" wrote:

Is the range from G3 to the last row of data in G?

This may not be the most elegant, but it works

Sub Test()
Dim myWS As Worksheet
Dim myRange As Range
Dim r As Range
Dim lRow As Long

Set myWS = Worksheets("MMS for CP")
lRow = myWS.Cells(myWS.Rows.Count, "G").End(xlUp).Row
Set myRange = myWS.Range("G3").Resize(lRow - 3 + 1, 1)

For Each r In myRange
r.Value = Replace(r.Value, " ", "")
Next r

End Sub

--
HTH,
Barb Reinhardt



"Paige" wrote:

It's suppose to tell it what range to do the find/replace.

"Barb Reinhardt" wrote:

What's the intent of this line?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select

I'm guessing that's part of the problem.
--
HTH,
Barb Reinhardt



"Paige" wrote:

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Designating Sheet vs Workbook When Doing Find/Replace

Add

Application.Calculation = XLCalculationManual
Application.ScreenUpdating= False

at the beginning

Application.Calculation = XLCalculationAutomatic
Application.ScreenUpdating= True

At the end.
--
HTH,
Barb Reinhardt



"Paige" wrote:

Hi, Barb. The range is from G3 to the last row of data in G. I'm trying not
to use the "for each....next" method because there are so many rows and it
adds too much processing time. That's why I was trying to do Find/Replace,
but can't seem to tell it to make sure and only do that within the specified
range and not within the entire workbook. If you go to Edit | Replace in
Excel, the Find and Replace dialog box gives you an option to do this within
workbook or sheet, but I don't know how to do it with code.

"Barb Reinhardt" wrote:

Is the range from G3 to the last row of data in G?

This may not be the most elegant, but it works

Sub Test()
Dim myWS As Worksheet
Dim myRange As Range
Dim r As Range
Dim lRow As Long

Set myWS = Worksheets("MMS for CP")
lRow = myWS.Cells(myWS.Rows.Count, "G").End(xlUp).Row
Set myRange = myWS.Range("G3").Resize(lRow - 3 + 1, 1)

For Each r In myRange
r.Value = Replace(r.Value, " ", "")
Next r

End Sub

--
HTH,
Barb Reinhardt



"Paige" wrote:

It's suppose to tell it what range to do the find/replace.

"Barb Reinhardt" wrote:

What's the intent of this line?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select

I'm guessing that's part of the problem.
--
HTH,
Barb Reinhardt



"Paige" wrote:

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Designating Sheet vs Workbook When Doing Find/Replace

Are you having trouble with that first line of code?

If MMS for CP isn't the activesheet, then I would expect that line to cause an
error.

with worksheets("mms for cp")
with .range("g3",.cells(.rows.count,"G").end(xlup))
.cells.replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
end with
end with

Those unqualified ranges will refer to the activesheet (if the code is in a
general module)--or the sheet that owns the code if the code is behind a
worksheet.



Paige wrote:

This code is suppose to remove excess spaces from the specified range.
However, it sometimes thinks I mean to do this within the entire workbook,
versus the range on the specified sheet. Have not been able to figure out
how to adjust this so that it knows to only do this within a specific range.
Can someone please help?

Worksheets("MMS for CP").Range(Range("G3"), Range("G65536").End(xlUp)).Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False,
ReplaceFormat:=False


--

Dave Peterson
Reply
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
Find/Replace Event or Find/Replace for Protected Sheet ... Joe HM Excel Programming 2 October 27th 07 03:55 PM
find replace within sheet or workbook mcphc Excel Programming 5 April 23rd 07 03:28 PM
find and replace within workbook macro CVL Excel Discussion (Misc queries) 1 February 9th 06 10:32 PM
Designating a workbook reference base on a cells contents PCLIVE Excel Worksheet Functions 2 December 23rd 05 04:54 PM
find and replace, within workbook Matt Carter Excel Discussion (Misc queries) 1 November 22nd 05 12:55 AM


All times are GMT +1. The time now is 03:20 PM.

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"