Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Problem with Find method

I have a function in a duty roster spreadsheet which uses the find method to
find the word "Holiday" and determine who should pull duty on that day. Code
is below.

It seems to work ok until it goes on to the Set d= .FindNext(d) line. Then
I get an Object Variable or With Block Variable Not Set error.

One other called function (Step_2) uses the Find method. Would this be
re-setting the With block? How can I prevent this, or get around it? Should
I be using subs instead of functions?

There are three worksheets, the Master, a staff sheet, and a sheet that has
everyone's vacation days.
code below.
--
TIA

JonR
-------------------------------------------------------------------------------------
Function Assign_Holiday()

Worksheets("DCSIS Master").Activate

Cells(1, 3).Activate

inX1 = ActiveCell.End(xlDown).Row 'finds the first empty slot inthe duty
roster,

'after the first empty slot, first holidays are populated, the weekends,
then the rest
'the "weekend" code is suffering the same problem

With Worksheets("DCSIS Master").Range(Cells(inX1, 2), Cells(inEnd, 2))
Set d = .Find("HOLIDAY", LookIn:=xlValues)
If Not d Is Nothing Then
firsthAddress = d.Address
Do
blHoliday = True
inRow = d.Row

dtDate = Cells(inRow, 1).Value

If Cells(inRow - 1, 2).Value = "WEEKEND" Then ' check for
weekend holiday

blWeekend = True

End If

Do Until blAvail = True

Step_2 'looks for the next available person

Loop

Step_3 ' populates the duty roster

blAvail = False

Set d = .FindNext(d)

Loop While Not d Is Nothing And d.Address < firsthAddress

End If
End With
End Function
--------------------------------------------------------------------------------------------

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Problem with Find method

Jon,

You can only use the FindNext with the conditions of the last time find was
used. Try using the full find method again instead of FindNext. I have found
that this works.

Also, check out the Find Method in Help. Click on Show All and in the
remarks well down the page you will see a comment like this:-

The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each
time you use this method. If you dont specify values for these arguments the
next time you call the method, the saved values are used. Setting these
arguments changes the settings in the Find dialog box, and changing the
settings in the Find dialog box changes the saved values that are used if you
omit the arguments. To avoid problems, set these arguments explicitly each
time you use this method.

These arguments are even saved from a find done in the interactive mode and
therfore they should always be reset.

Regards,

OssieMac


"JonR" wrote:

I have a function in a duty roster spreadsheet which uses the find method to
find the word "Holiday" and determine who should pull duty on that day. Code
is below.

It seems to work ok until it goes on to the Set d= .FindNext(d) line. Then
I get an Object Variable or With Block Variable Not Set error.

One other called function (Step_2) uses the Find method. Would this be
re-setting the With block? How can I prevent this, or get around it? Should
I be using subs instead of functions?

There are three worksheets, the Master, a staff sheet, and a sheet that has
everyone's vacation days.
code below.
--
TIA

JonR
-------------------------------------------------------------------------------------
Function Assign_Holiday()

Worksheets("DCSIS Master").Activate

Cells(1, 3).Activate

inX1 = ActiveCell.End(xlDown).Row 'finds the first empty slot inthe duty
roster,

'after the first empty slot, first holidays are populated, the weekends,
then the rest
'the "weekend" code is suffering the same problem

With Worksheets("DCSIS Master").Range(Cells(inX1, 2), Cells(inEnd, 2))
Set d = .Find("HOLIDAY", LookIn:=xlValues)
If Not d Is Nothing Then
firsthAddress = d.Address
Do
blHoliday = True
inRow = d.Row

dtDate = Cells(inRow, 1).Value

If Cells(inRow - 1, 2).Value = "WEEKEND" Then ' check for
weekend holiday

blWeekend = True

End If

Do Until blAvail = True

Step_2 'looks for the next available person

Loop

Step_3 ' populates the duty roster

blAvail = False

Set d = .FindNext(d)

Loop While Not d Is Nothing And d.Address < firsthAddress

End If
End With
End Function
--------------------------------------------------------------------------------------------

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Problem with Find method

Jon,

Forgot something before. If you use the full find method instead of findnext
then you need to save the previous find address and set the after argument
like this:-

saveAddre = d.Address 'Set immediately after the first find

Set d = .Find(What:="jim", after:=Range(saveAddre), _
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)

saveAddre = d.Address 'Set after each successive find

Regards,

OssieMac

"OssieMac" wrote:

Jon,

You can only use the FindNext with the conditions of the last time find was
used. Try using the full find method again instead of FindNext. I have found
that this works.

Also, check out the Find Method in Help. Click on Show All and in the
remarks well down the page you will see a comment like this:-

The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each
time you use this method. If you dont specify values for these arguments the
next time you call the method, the saved values are used. Setting these
arguments changes the settings in the Find dialog box, and changing the
settings in the Find dialog box changes the saved values that are used if you
omit the arguments. To avoid problems, set these arguments explicitly each
time you use this method.

These arguments are even saved from a find done in the interactive mode and
therfore they should always be reset.

Regards,

OssieMac


"JonR" wrote:

I have a function in a duty roster spreadsheet which uses the find method to
find the word "Holiday" and determine who should pull duty on that day. Code
is below.

It seems to work ok until it goes on to the Set d= .FindNext(d) line. Then
I get an Object Variable or With Block Variable Not Set error.

One other called function (Step_2) uses the Find method. Would this be
re-setting the With block? How can I prevent this, or get around it? Should
I be using subs instead of functions?

There are three worksheets, the Master, a staff sheet, and a sheet that has
everyone's vacation days.
code below.
--
TIA

JonR
-------------------------------------------------------------------------------------
Function Assign_Holiday()

Worksheets("DCSIS Master").Activate

Cells(1, 3).Activate

inX1 = ActiveCell.End(xlDown).Row 'finds the first empty slot inthe duty
roster,

'after the first empty slot, first holidays are populated, the weekends,
then the rest
'the "weekend" code is suffering the same problem

With Worksheets("DCSIS Master").Range(Cells(inX1, 2), Cells(inEnd, 2))
Set d = .Find("HOLIDAY", LookIn:=xlValues)
If Not d Is Nothing Then
firsthAddress = d.Address
Do
blHoliday = True
inRow = d.Row

dtDate = Cells(inRow, 1).Value

If Cells(inRow - 1, 2).Value = "WEEKEND" Then ' check for
weekend holiday

blWeekend = True

End If

Do Until blAvail = True

Step_2 'looks for the next available person

Loop

Step_3 ' populates the duty roster

blAvail = False

Set d = .FindNext(d)

Loop While Not d Is Nothing And d.Address < firsthAddress

End If
End With
End Function
--------------------------------------------------------------------------------------------

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Problem with Find method

Thanks OssieMac

With your suggestions I was able to come up with a working solution
--
JonR


"OssieMac" wrote:

Jon,

Forgot something before. If you use the full find method instead of findnext
then you need to save the previous find address and set the after argument
like this:-

saveAddre = d.Address 'Set immediately after the first find

Set d = .Find(What:="jim", after:=Range(saveAddre), _
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)

saveAddre = d.Address 'Set after each successive find

Regards,

OssieMac

"OssieMac" wrote:

Jon,

You can only use the FindNext with the conditions of the last time find was
used. Try using the full find method again instead of FindNext. I have found
that this works.

Also, check out the Find Method in Help. Click on Show All and in the
remarks well down the page you will see a comment like this:-

The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each
time you use this method. If you dont specify values for these arguments the
next time you call the method, the saved values are used. Setting these
arguments changes the settings in the Find dialog box, and changing the
settings in the Find dialog box changes the saved values that are used if you
omit the arguments. To avoid problems, set these arguments explicitly each
time you use this method.

These arguments are even saved from a find done in the interactive mode and
therfore they should always be reset.

Regards,

OssieMac


"JonR" wrote:

I have a function in a duty roster spreadsheet which uses the find method to
find the word "Holiday" and determine who should pull duty on that day. Code
is below.

It seems to work ok until it goes on to the Set d= .FindNext(d) line. Then
I get an Object Variable or With Block Variable Not Set error.

One other called function (Step_2) uses the Find method. Would this be
re-setting the With block? How can I prevent this, or get around it? Should
I be using subs instead of functions?

There are three worksheets, the Master, a staff sheet, and a sheet that has
everyone's vacation days.
code below.
--
TIA

JonR
-------------------------------------------------------------------------------------
Function Assign_Holiday()

Worksheets("DCSIS Master").Activate

Cells(1, 3).Activate

inX1 = ActiveCell.End(xlDown).Row 'finds the first empty slot inthe duty
roster,

'after the first empty slot, first holidays are populated, the weekends,
then the rest
'the "weekend" code is suffering the same problem

With Worksheets("DCSIS Master").Range(Cells(inX1, 2), Cells(inEnd, 2))
Set d = .Find("HOLIDAY", LookIn:=xlValues)
If Not d Is Nothing Then
firsthAddress = d.Address
Do
blHoliday = True
inRow = d.Row

dtDate = Cells(inRow, 1).Value

If Cells(inRow - 1, 2).Value = "WEEKEND" Then ' check for
weekend holiday

blWeekend = True

End If

Do Until blAvail = True

Step_2 'looks for the next available person

Loop

Step_3 ' populates the duty roster

blAvail = False

Set d = .FindNext(d)

Loop While Not d Is Nothing And d.Address < firsthAddress

End If
End With
End Function
--------------------------------------------------------------------------------------------

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
Find Method problem in Excel VBA.... Irmann Excel Worksheet Functions 7 March 10th 08 03:49 AM
Problem with Find method IanC Excel Programming 7 September 29th 06 04:34 PM
Problem with Find Method Edward Ulle Excel Programming 4 November 22nd 05 05:00 PM
Problem with the FIND method looking for dates. jase[_2_] Excel Programming 2 November 14th 05 01:30 PM
Problem with find method Ralph Heidecke[_2_] Excel Programming 3 April 18th 05 08:07 PM


All times are GMT +1. The time now is 06:05 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"