LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default Problem running Find code for different sheet

Here is a macro that works. It will find a record in a sheet named
Official List via a PO# given by the user.


Sub FindFirst()
'This is for the PO/PL search via UserForm12. Clicking the OK button
'brings you here. If record found, it opens up UserForm13 to show
'that record. The "Find Another Record" button will also loop back
here.

Set rngToSearch = Sheets("Official List").Columns("J")
Set rngFound = rngToSearch.Find(What:=FindPOVal, _
LookIn:=xlValues)

If rngFound Is Nothing Then
MsgBox "This record was not found. You might want to check the
Deleted List. Go to the Navigator for 'Find Deleted Record' button."

Else
strFirst = rngFound.Address
rngFound.Select
Unload UserForm12
UserForm13.Show

End If

End Sub

In the Declarations in the same module, I have this:
Private rngToSearch As Range
Private rngFound As Range
Public strFirst As String
Public FindPOVal As String

I wanted to duplicate this proceedure in another sub that will find a
record in a sheet named Deleted List, that is in the same workbook. It
will then open up different userforms than is shown above. (a different
look at the records)
Here is the Find code to look for a record in the Deleted List:

Sub FindDeleted()
'Same routine as FindFirst, except that this searches the Deleted List.

Set rngToSearch = Sheets("Deleted List").Columns("J")
Set rngFound = rngToSearch.Find(What:=FindPOVal, _
LookIn:=xlValues)

If rngFound Is Nothing Then
MsgBox "The record you requested was not found on this list."

Else
strFirst = rngFound.Address
rngFound.Select '<<<error is at this line
Unload UserForm14
UserForm15.Show

End If

End Sub

As you can see, then only thing different is the sheet name, and the
userforms involved.

I get an error in the Else section in the line
rngFound.Select

Does this error have to do with the Declarations statements? Is there a
problem with using these same statements to execute the Find in both
subs?
Anybody have a solution? I'm sure it's something simple. But, probably
about something I haven't learned yet.
Thanks
J.O.

 
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
Problem Running Code in Excel 2003 Mark Excel Programming 1 June 17th 05 12:45 AM
Problem running code behind a userform cdb Excel Programming 17 February 10th 05 03:53 PM
Problem with Running VBA code on Cell Change Marty Excel Programming 8 January 18th 05 04:01 AM
VBA and determining which sheet the code is running under jake Excel Programming 2 April 28th 04 04:43 PM
Running Code on Each Sheet in an Excel Workbook bearie Excel Programming 2 February 6th 04 03:54 PM


All times are GMT +1. The time now is 10:25 AM.

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

About Us

"It's about Microsoft Excel"