Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting ranges 1

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
Hello All,

I can use the following code to set a range where I look to see if a string is within another workbook

Set rcell = Workbooks("WestArea2003.xls").ActiveSheet.Range("B:B").Find(what:=blah, lookat:=xlPart, searchorder:=xlColumns)

Then i can say If rcell Is Nothing Then...
Else....

But now that i try to use the same thing to see if a worksheet is within a workbook, it doesnt work

Set rcell = Workbooks("WestArea2003.xls").Worksheets("Nonexistant worksheet")

So is there anyway to apply the same principle to set a worksheet as a range and then test to see if it is Nothing or Not Nothing, thanks!
 
Close, but not quite. Try this:
[blue]
Code:
Sub test()
Dim oSheet As Worksheet
  On Error Resume Next
  Set oSheet = Workbooks("WestArea2003.xls").Worksheets("Nonexistant worksheet")
  If oSheet Is Nothing Then
    MsgBox "no such sheet"
  End If
End Sub
[/color]

 
THAT'S SWEEET AND SMART TOO, YOUR GETTING A STAR FOR THAT!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top