Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
crj crj is offline
external usenet poster
 
Posts: 5
Default 2 finds/findnext in nested loops

I am trying to build a table that lists projects and hours worked for that
project for each day of the week.

I start by doing a find on my timesheet sheet for a certain date if I find
an entry for that date I then want to do a find on my project number column
on the display sheet to see if that project already has an entry (if it
does I want to add more hours for that date). I have this working ok my
problem is that when I finish checking for the project number I exit out of
that loop and fall back into the loop looking for the date and this find next
is trying match on the project number instead of the date.

Here is the code example:
With timesheetRange
Set C = .Find(datetofind, LookIn:=xlValues)
If Not C Is Nothing Then
firstAddress = C.Address
Do
rowfound = C.Row
AlreadyUpdated = False
projectToUpdate = Worksheets("Timesheet").Range("C" &
rowfound).Value

With Worksheets("ProjectDB").Range("B22:C" & pdbLR)
Set pdbC = .Find(projectToUpdate, LookIn:=xlValues)
If Not pdbC Is Nothing Then
pdbfirstAddress = pdbC.Address
Do
pdbrowfound = pdbC.Row
'Select
If Worksheets("ProjectDB").Range("C" & pdbrowfound).Value
= Worksheets("Timesheet").Range("E" & rowfound).Value Then
'add Hours
Worksheets("ProjectDB").Range("E" & pdbrowfound).Value
= Worksheets("Timesheet").Range("D" & rowfound).Value
AlreadyUpdated = True
End If
Set pdbC = .FindNext(pdbC)
Loop While Not pdbC Is Nothing And pdbC.Address <
pdbfirstAddress
End If
End With
€˜ If we havent updated then we must need to add a line
If Not AlreadyUpdated Then
'Project #
Worksheets("projectdb").Range("B" & pdbNextline).Value =
Worksheets("timesheet").Range("C" & rowfound).Value
'Activity
Worksheets("projectdb").Range("C" & pdbNextline).Value =
Worksheets("timesheet").Range("E" & rowfound).Value
'Hours
Worksheets("projectdb").Range("D" & pdbNextline).Value =
Worksheets("timesheet").Range("D" & rowfound).Value
pdbNextline = pdbNextline + 1
End If
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 2 finds/findnext in nested loops


You can't used findnext recusively. The findnext uses the last find's
what property. You have to use find instead of findnext. Try this
chage


from
Set C = .FindNext(C)
to
Set C = .Find(datetofind, after:=c, LookIn:=xlValues)


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193644

http://www.thecodecage.com/forumz

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
need help with nested for-next loops rpw Excel Programming 6 September 18th 07 04:38 PM
Help with nested for loops [email protected] Excel Programming 5 May 2nd 07 05:30 PM
Nested with loops Clair[_2_] Excel Programming 1 March 20th 06 07:29 PM
nested for loops and end for SandyR Excel Programming 3 October 6th 05 09:36 PM
Nested loops?? CG Rosén Excel Programming 1 June 22nd 04 08:07 PM


All times are GMT +1. The time now is 06:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"