PC Review


Reply
Thread Tools Rate Thread

2 finds/findnext in nested loops

 
 
crj
Guest
Posts: n/a
 
      7th Apr 2010
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 haven’t 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with nested for loops yousaf.hassan@gmail.com Microsoft Excel Worksheet Functions 5 2nd May 2007 05:30 PM
nested loops =?Utf-8?B?amVy?= Microsoft Excel Programming 2 15th Jan 2006 09:09 PM
Nested Loops =?Utf-8?B?V2luZ2Vy?= Microsoft Access VBA Modules 1 3rd Jun 2005 01:38 PM
Nested loops?? CG Rosén Microsoft Excel Programming 1 22nd Jun 2004 08:07 PM
nested for loops dawn Microsoft C# .NET 5 31st Oct 2003 11:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:36 PM.