Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default I need to stop this Loop

Hi all

This works but I have to press Esc key to stop the macro. I've been reading
up on loops but need more time to work with them.

Sub ChangeNames()

Sheets("Sheet2").Select
Application.Goto Reference:="R2C5"

Do
Cells.Find(What:="Test1", After:=ActiveCell, LookIn:=xlValues, LookAt:=
_
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

Sheets("Tests htmls").Select
Application.Goto Reference:="R1C1"
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Loop Until IsEmpty(ActiveCell.Offset(0, 0))

End Sub

I also have items in A2 to A37 "Tests htmls" I'd like to change in sheet2
col E, is there a way to do this all in one macro, rather than have 37
macros.

Thanks in advace

Dave


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default I need to stop this Loop

What is the purpose of Looping in this code. The Loop will only end if A1
or R1C1 of sheet "Tests htmls" is empty. If it wasn't empty the first time
through, then it won't be empty the second time or any other time unless you
empty it yourself. Therefore, the Loop will never end.

Additionally, in the last line, the "Offset" is unnecessary since you are
not offsetting anything.

Replace - Loop Until IsEmpty(ActiveCell.Offset(0, 0))
With - Loop Until IsEmpty(ActiveCell)

HTH,
Paul

--

"DaveM" wrote in message
...
Hi all

This works but I have to press Esc key to stop the macro. I've been
reading up on loops but need more time to work with them.

Sub ChangeNames()

Sheets("Sheet2").Select
Application.Goto Reference:="R2C5"

Do
Cells.Find(What:="Test1", After:=ActiveCell, LookIn:=xlValues, LookAt:=
_
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

Sheets("Tests htmls").Select
Application.Goto Reference:="R1C1"
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Loop Until IsEmpty(ActiveCell.Offset(0, 0))

End Sub

I also have items in A2 to A37 "Tests htmls" I'd like to change in sheet2
col E, is there a way to do this all in one macro, rather than have 37
macros.

Thanks in advace

Dave




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default I need to stop this Loop

Sub ChangeNames()
Dim rng As Range
Dim sAddr As String
With Sheets("Sheet2").Cells
Set rng = .Find(What:="Test1", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not rng Is Nothing Then
sAddr = rng.Address
Do
rng.Value = Sheets("Tests htmls").Range("A1")
Set rng = .FindNext(rng)
Loop Until rng Is Nothing
End If
End With
End Sub

You would need a list of what values are replaced with what. Perhaps you
could put this in Tests htmls in column B next to your values in column A.

So A1:A37 contain the values to use as replacements
B1:B37 contain the values that will be replaced.

Since your using xlPart, make sure you don't have any situations where one
value is a substring of another value.

Sub ChangeAllNames()
Dim cell As Range, rng As Range
Dim sAddr As String
For Each cell In Worksheets( _
"Tests htmls").Range("A1:A37")
Debug.Print cell, cell.Offset(0, 1)
With Sheets("Sheet2").Cells
Set rng = .Find( _
What:=cell.Offset(0, 1).Value, _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not rng Is Nothing Then
Debug.Print "--" & rng.Address
sAddr = rng.Address
Do
rng.Value = cell
Set rng = .FindNext(rng)
Loop Until rng Is Nothing
End If
End With
Next cell
End Sub
--
Regards,
Tom Ogilvy


"DaveM" wrote:

Hi all

This works but I have to press Esc key to stop the macro. I've been reading
up on loops but need more time to work with them.

Sub ChangeNames()

Sheets("Sheet2").Select
Application.Goto Reference:="R2C5"

Do
Cells.Find(What:="Test1", After:=ActiveCell, LookIn:=xlValues, LookAt:=
_
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

Sheets("Tests htmls").Select
Application.Goto Reference:="R1C1"
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Loop Until IsEmpty(ActiveCell.Offset(0, 0))

End Sub

I also have items in A2 to A37 "Tests htmls" I'd like to change in sheet2
col E, is there a way to do this all in one macro, rather than have 37
macros.

Thanks in advace

Dave



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default I need to stop this Loop

Thanks for your help


"Tom Ogilvy" wrote in message
...
Sub ChangeNames()
Dim rng As Range
Dim sAddr As String
With Sheets("Sheet2").Cells
Set rng = .Find(What:="Test1", _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not rng Is Nothing Then
sAddr = rng.Address
Do
rng.Value = Sheets("Tests htmls").Range("A1")
Set rng = .FindNext(rng)
Loop Until rng Is Nothing
End If
End With
End Sub

You would need a list of what values are replaced with what. Perhaps you
could put this in Tests htmls in column B next to your values in column A.

So A1:A37 contain the values to use as replacements
B1:B37 contain the values that will be replaced.

Since your using xlPart, make sure you don't have any situations where one
value is a substring of another value.

Sub ChangeAllNames()
Dim cell As Range, rng As Range
Dim sAddr As String
For Each cell In Worksheets( _
"Tests htmls").Range("A1:A37")
Debug.Print cell, cell.Offset(0, 1)
With Sheets("Sheet2").Cells
Set rng = .Find( _
What:=cell.Offset(0, 1).Value, _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not rng Is Nothing Then
Debug.Print "--" & rng.Address
sAddr = rng.Address
Do
rng.Value = cell
Set rng = .FindNext(rng)
Loop Until rng Is Nothing
End If
End With
Next cell
End Sub
--
Regards,
Tom Ogilvy


"DaveM" wrote:

Hi all

This works but I have to press Esc key to stop the macro. I've been
reading
up on loops but need more time to work with them.

Sub ChangeNames()

Sheets("Sheet2").Select
Application.Goto Reference:="R2C5"

Do
Cells.Find(What:="Test1", After:=ActiveCell, LookIn:=xlValues,
LookAt:=
_
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

Sheets("Tests htmls").Select
Application.Goto Reference:="R1C1"
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Loop Until IsEmpty(ActiveCell.Offset(0, 0))

End Sub

I also have items in A2 to A37 "Tests htmls" I'd like to change in sheet2
col E, is there a way to do this all in one macro, rather than have 37
macros.

Thanks in advace

Dave





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
Stop Loop pjd33 Excel Programming 4 May 24th 07 05:21 PM
Do Loop doesn't stop [email protected][_2_] Excel Programming 5 May 22nd 07 07:32 PM
Stop Loop Robert[_30_] Excel Programming 2 January 17th 07 01:34 PM
how to stop a loop L775 Excel Programming 6 November 29th 04 08:37 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 04:10 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"