loop with array

J

John

The following code pops up my msg box... meaning it doesn't find what I am
looking for. Any ideas why? Thanks for the help.

John


Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range
Dim DestCell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wks = Sheets("data")
Set rngToSearch = Range("j7:j712")

Set rngFound = rngToSearch.Find(what:=Array(Range("d1").Value,
Range("d2").Value, Range("d3").Value, Range("d4").Value), LookIn:=xlValues,
lookat:=xlWhole)
If rngFound Is Nothing Then
Range("a6").Select
MsgBox "No new Floaters"
Else
Do
With Worksheets("vlookup")
Set DestCell = Range("a800").End(xlDown).Offset(1, 0)
End With
rngFound.EntireRow.Copy _
Destination:=DestCell
Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Sheets("data").Select
Range("a6").Select
End Sub
 
J

John

If it makes a difference, the values in column D and what I am trying to find
are dates...
 
J

John

I changed the lookat:= to Lookat:= and it began to run... however it stays on
the same row, stuck in a continual loop and ideas on that?
 
D

Dave Peterson

I didn't look too closely at your code, but this line jumped out at me:

Set rngFound = rngToSearch.Find(what:=Array(Range("d1").Value,
Range("d2").Value, Range("d3").Value, Range("d4").Value), LookIn:=xlValues,
lookat:=xlWhole)

I would think you'd want to loop through those ranges and do your individual
finds.

dim myRng as range
dim myCell as range
dim FoundIt as boolean

with activesheet
set myrng = range("d1:d4")
end with

foundit = false
for each mycell in myrng.cells
Set rngFound = rngToSearch.Find(what:=mycell.Value), LookIn:=xlValues,
lookat:=xlWhole)
if rngfound is nothing then
'keep looking
else
foundit = true
exit for
end if
next mycell

if foundit = false then
'....
 
D

Dave Peterson

If Jim's code isn't working, I think you may want to take the time to post what
you want the code to do--in plain old words.

And I'm sure Jim will be able to help once he understands your objective.
 
J

John

I am sure he will be able to as well, I just thought you may catch something
we are missing. Another perspective never hurt... and I believe he knows
what I am trying to do quite well.
 

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

Similar Threads

Please help! 9
Delete rows macro 3
Find and loop help-multiple columns 4
Find next problem 1
Test variable range for 'Delete'; then delete the row 2
copy and paste a row 16
help with macro 9
findnext error in loop 2

Top