head spinning loop...

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

At least it's making my head spin...

Sheet1 has sections so that A32 - A81 is part of one section. I want to
loop through all the values in Sheet2, column D and if those values begin
with "6" then take the value from the same row in column E and place it in
Sheet1 starting from row A32 and filling downward for every instance in
Sheet2 where the value begins with "6".

Please help!
 
Give this a try...

Sub CopyStuff()
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet2").Columns("D")
Set rngFound = rngToSearch.Find(What:="6*", _
LookAt:=xlWhole, _
LookIn:=xlFormulas)
If Not rngFound Is Nothing Then
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
rngFoundAll.Offset(0, 1).Copy Sheets("Sheet1").Range("A32")
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top