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 nested find/find next

I am trying to find all ted for timesheet records for a certain date. Once I
find a record I need to do another find to see if I have a display line
already created for that project number. If I do I want to update it rather
than create a new lne.

My problem is that when I go to my next date the findnext looks for project
rather than date (find next runs against last find rather than the first find)

here is the code:
Application.Goto Sheets("Timesheet").Range("B2")
LR = Cells(Rows.Count, 2).End(xlUp).Row
Set tsRange = Worksheets("Timesheet").Range("B2:E" & LR)

Set refRange = Worksheets("Reference").Range("C5")
Set pdbRange = Worksheets("ProjectDB").Range("B:J")

Application.Goto Sheets("ProjectDB").Range("B22")
pdbLR = Cells(Rows.Count, 2).End(xlUp).Row

If pdbLR 21 Then
Range("B22:J" & pdbLR).Select
Selection.ClearContents
End If

Range("B22:B" & pdbLR).Select
Selection.NumberFormat = "0000000000"

pdbNextline = 22

For i = 1 To 7
If i = 1 Then datetofind = CDate(refRange.Value - 6)
If i = 2 Then datetofind = CDate(refRange.Value - 5)
If i = 3 Then datetofind = CDate(refRange.Value - 4)
If i = 4 Then datetofind = CDate(refRange.Value - 3)
If i = 5 Then datetofind = CDate(refRange.Value - 2)
If i = 6 Then datetofind = CDate(refRange.Value - 1)
If i = 7 Then datetofind = CDate(refRange.Value)

With tsRange
Set c = .Find(datetofind, LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
rowfound = c.Row
If i = 1 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
If i = 2 Then
Application.Goto Sheets("ProjectDB").Range("B22")
pdbLR = Cells(Rows.Count, 2).End(xlUp).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)
If pdbc Is Nothing Then Exit Do
If pdbc.Address = pdbfirstAddress Then Exit Do
Loop
End If
End With
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("E" & pdbNextline).Value =
Worksheets("timesheet").Range("D" & rowfound).Value
pdbNextline = pdbNextline + 1
End If
End If 'i=2
If i = 3 Then

End If 'i=3
If i = 4 Then

End If 'i=4
If i = 5 Then

End If 'i=5
If i = 6 Then

End If 'i=6
If i = 7 Then

End If 'i=7
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < FirstAddress
End If
End With
Next i
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default nested find/find next

See Find Method here;
http://www.ozgrid.com/VBA/find-method.htm
and scroll down to "Find_Bold_Cat"

If your dates are NOT US format, look here as well;
http://www.ozgrid.com/VBA/find-dates.htm


--
Regards
Dave Hawley
www.ozgrid.com
"crj" wrote in message
...
I am trying to find all ted for timesheet records for a certain date. Once
I
find a record I need to do another find to see if I have a display line
already created for that project number. If I do I want to update it
rather
than create a new lne.

My problem is that when I go to my next date the findnext looks for
project
rather than date (find next runs against last find rather than the first
find)

here is the code:
Application.Goto Sheets("Timesheet").Range("B2")
LR = Cells(Rows.Count, 2).End(xlUp).Row
Set tsRange = Worksheets("Timesheet").Range("B2:E" & LR)

Set refRange = Worksheets("Reference").Range("C5")
Set pdbRange = Worksheets("ProjectDB").Range("B:J")

Application.Goto Sheets("ProjectDB").Range("B22")
pdbLR = Cells(Rows.Count, 2).End(xlUp).Row

If pdbLR 21 Then
Range("B22:J" & pdbLR).Select
Selection.ClearContents
End If

Range("B22:B" & pdbLR).Select
Selection.NumberFormat = "0000000000"

pdbNextline = 22

For i = 1 To 7
If i = 1 Then datetofind = CDate(refRange.Value - 6)
If i = 2 Then datetofind = CDate(refRange.Value - 5)
If i = 3 Then datetofind = CDate(refRange.Value - 4)
If i = 4 Then datetofind = CDate(refRange.Value - 3)
If i = 5 Then datetofind = CDate(refRange.Value - 2)
If i = 6 Then datetofind = CDate(refRange.Value - 1)
If i = 7 Then datetofind = CDate(refRange.Value)

With tsRange
Set c = .Find(datetofind, LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
rowfound = c.Row
If i = 1 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
If i = 2 Then
Application.Goto Sheets("ProjectDB").Range("B22")
pdbLR = Cells(Rows.Count, 2).End(xlUp).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)
If pdbc Is Nothing Then Exit Do
If pdbc.Address = pdbfirstAddress Then Exit Do
Loop
End If
End With
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("E" & pdbNextline).Value =
Worksheets("timesheet").Range("D" & rowfound).Value
pdbNextline = pdbNextline + 1
End If
End If 'i=2
If i = 3 Then

End If 'i=3
If i = 4 Then

End If 'i=4
If i = 5 Then

End If 'i=5
If i = 6 Then

End If 'i=6
If i = 7 Then

End If 'i=7
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < FirstAddress
End If
End With
Next i


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
Nested MID and FIND - OR? Brenda Excel Worksheet Functions 3 January 14th 10 01:58 AM
Use of Find with Left, Mid, Right functions in nested IF(and('s MJW[_2_] Excel Discussion (Misc queries) 8 September 20th 07 09:22 PM
Nested IF, reports incorrectly, can't find anything like it to ref Chris T-M Excel Worksheet Functions 6 September 12th 07 03:20 PM
Nested function 'FIND(OR)' JE McGimpsey Excel Programming 3 September 28th 04 09:27 PM
Nested Find problem MikeR[_2_] Excel Programming 1 July 14th 03 12:17 AM


All times are GMT +1. The time now is 06:59 AM.

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"