ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   head spinning loop... (https://www.excelbanter.com/excel-programming/401604-head-spinning-loop.html)

Stephen[_24_]

head spinning loop...
 
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!

Jim Thomlinson

head spinning loop...
 
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
--
HTH...

Jim Thomlinson


"Stephen" wrote:

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!



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com