Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default many types of loops

So I am trying to do a loop. I used the excel help but its not that
helpful. I am currently trying to do a find loop but also when the
word is found it is copy and pasted into a new column. That works
great but when I try to loop it so that it finds the next word to copy
and paste it pastes right over the old one. It also just keeps running
forever. It just keeps looping. So hopefully I can get some help from
you geniuses.

Dim y As Integer
Dim rng1 As Range
For y = 1 To 30 Step 4
With Worksheets(1).Range("a1:a500")
Set c = .Find("Item # 2", LookIn:=xlValues)
If Not c Is Nothing Then
Do
Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
Range(Cells(y, 3), Cells(y, 4)).PasteSpecial

Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress <----
not sure if neccesary its what was in the help.

End If
End With
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default many types of loops

For the problem of results being pasted on top of one another, your
PasteSpecial cell never changes because y is outside the Do loop. As for
the infinite loop, take a look at the unhelpful help article again :-)

"When the search reaches the end of the specified search range, it wraps
around to the beginning of the range. To stop a search when this wraparound
occurs, save the address of the first found cell, and then test each
successive found-cell address against this saved address."

This is why they compare c.Address to firstAddress, but you left out the
firstAddress = c.Address line

Try something like this (NOT TESTED!)

With Worksheets(1).Range("A1:A500)
Set c = .Find("Item # 2", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
y = 1
Do
Range(c.Offset(0,0), c.Offset(3,1)).Copy
Range(Cells(y,3), Cells(y,4)).PasteSpecial
Set c = .FindNext(c)
y = y + 4 <-------Adjust as needed
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With


wrote in message
ups.com...
So I am trying to do a loop. I used the excel help but its not that
helpful. I am currently trying to do a find loop but also when the
word is found it is copy and pasted into a new column. That works
great but when I try to loop it so that it finds the next word to copy
and paste it pastes right over the old one. It also just keeps running
forever. It just keeps looping. So hopefully I can get some help from
you geniuses.

Dim y As Integer
Dim rng1 As Range
For y = 1 To 30 Step 4
With Worksheets(1).Range("a1:a500")
Set c = .Find("Item # 2", LookIn:=xlValues)
If Not c Is Nothing Then
Do
Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
Range(Cells(y, 3), Cells(y, 4)).PasteSpecial

Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress <----
not sure if neccesary its what was in the help.

End If
End With
Next
End Sub



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
How can I hide unused file types from file types list in save dial Estra Q Excel Discussion (Misc queries) 1 December 17th 09 12:36 PM
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
For next loops Kate Excel Discussion (Misc queries) 5 May 22nd 06 01:11 PM
help with loops Rick B[_6_] Excel Programming 8 January 28th 04 12:32 AM
Loops PaulSinki Excel Programming 3 December 10th 03 05:01 PM


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