Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jc jc is offline
external usenet poster
 
Posts: 164
Default Finding a Sheet

I'm running an Access Database that creates worksheets in an Excel sheet.
The sheet is automatically named based on one of the criteria from the DB.
The problem I'm having is that I need to check if there is already a sheet in
the workbook with the same name as the one the DB is trying to use. I need
this to be part of the DB's coding, but can't seem to figure out a chunk of
code to to find the name of a worksheet. Any thoughts out there? I tried
the below, but that didn't work.

Sheets("Name_of_Sheet").Count

- Jeff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Finding a Sheet

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("Name_of_Sheet")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "Duplicate Sheet"
Else
'Do Stuff
End If


In article ,
JC wrote:

I'm running an Access Database that creates worksheets in an Excel sheet.
The sheet is automatically named based on one of the criteria from the DB.
The problem I'm having is that I need to check if there is already a sheet in
the workbook with the same name as the one the DB is trying to use. I need
this to be part of the DB's coding, but can't seem to figure out a chunk of
code to to find the name of a worksheet. Any thoughts out there? I tried
the below, but that didn't work.

Sheets("Name_of_Sheet").Count

- Jeff

  #3   Report Post  
Posted to microsoft.public.excel.programming
jc jc is offline
external usenet poster
 
Posts: 164
Default Finding a Sheet

This just prompts a "Run-time error '9': Subscript out of range" error.

- Jeff

"JE McGimpsey" wrote:

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("Name_of_Sheet")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "Duplicate Sheet"
Else
'Do Stuff
End If


In article ,
JC wrote:

I'm running an Access Database that creates worksheets in an Excel sheet.
The sheet is automatically named based on one of the criteria from the DB.
The problem I'm having is that I need to check if there is already a sheet in
the workbook with the same name as the one the DB is trying to use. I need
this to be part of the DB's coding, but can't seem to figure out a chunk of
code to to find the name of a worksheet. Any thoughts out there? I tried
the below, but that didn't work.

Sheets("Name_of_Sheet").Count

- Jeff


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Finding a Sheet

Replace

"Name_of_Sheet"

with your proposed worksheet name.

In article ,
JC wrote:

This just prompts a "Run-time error '9': Subscript out of range" error.

- Jeff

"JE McGimpsey" wrote:

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("Name_of_Sheet")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "Duplicate Sheet"
Else
'Do Stuff
End If


In article ,
JC wrote:

I'm running an Access Database that creates worksheets in an Excel sheet.

The sheet is automatically named based on one of the criteria from the
DB.
The problem I'm having is that I need to check if there is already a
sheet in
the workbook with the same name as the one the DB is trying to use. I
need
this to be part of the DB's coding, but can't seem to figure out a chunk
of
code to to find the name of a worksheet. Any thoughts out there? I
tried
the below, but that didn't work.

Sheets("Name_of_Sheet").Count

- Jeff


  #5   Report Post  
Posted to microsoft.public.excel.programming
jc jc is offline
external usenet poster
 
Posts: 164
Default Finding a Sheet

....um... yeah, I did that, not that green to all of this.

Don't worry about replying. I'll figure it out on my own.

- Jeff

"JE McGimpsey" wrote:

Replace

"Name_of_Sheet"

with your proposed worksheet name.

In article ,
JC wrote:

This just prompts a "Run-time error '9': Subscript out of range" error.

- Jeff

"JE McGimpsey" wrote:

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("Name_of_Sheet")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "Duplicate Sheet"
Else
'Do Stuff
End If


In article ,
JC wrote:

I'm running an Access Database that creates worksheets in an Excel sheet.

The sheet is automatically named based on one of the criteria from the
DB.
The problem I'm having is that I need to check if there is already a
sheet in
the workbook with the same name as the one the DB is trying to use. I
need
this to be part of the DB's coding, but can't seem to figure out a chunk
of
code to to find the name of a worksheet. Any thoughts out there? I
tried
the below, but that didn't work.

Sheets("Name_of_Sheet").Count

- Jeff




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Finding a Sheet

Don't get rid of those error checking lines that JE added, too.

With "on error resume next" there, you shouldn't have gotten the error on that
section of code.

JC wrote:

...um... yeah, I did that, not that green to all of this.

Don't worry about replying. I'll figure it out on my own.

- Jeff

"JE McGimpsey" wrote:

Replace

"Name_of_Sheet"

with your proposed worksheet name.

In article ,
JC wrote:

This just prompts a "Run-time error '9': Subscript out of range" error.

- Jeff

"JE McGimpsey" wrote:

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("Name_of_Sheet")
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "Duplicate Sheet"
Else
'Do Stuff
End If


In article ,
JC wrote:

I'm running an Access Database that creates worksheets in an Excel sheet.

The sheet is automatically named based on one of the criteria from the
DB.
The problem I'm having is that I need to check if there is already a
sheet in
the workbook with the same name as the one the DB is trying to use. I
need
this to be part of the DB's coding, but can't seem to figure out a chunk
of
code to to find the name of a worksheet. Any thoughts out there? I
tried
the below, but that didn't work.

Sheets("Name_of_Sheet").Count

- Jeff



--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Finding a Sheet

Hard to tell how green one is from a ng post.

I suspect you didn't add the On Error Resume Next code, since you
shouldn't have gotten a Subscript Out Of Range if you had.

If you did, I can only conclude that the error is elsewhere in your code.


In article ,
JC wrote:

...um... yeah, I did that, not that green to all of this.

Don't worry about replying. I'll figure it out on my own.

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
Finding Info from sheet 1 and removing only those rows from sheet Johnny B[_2_] Excel Discussion (Misc queries) 1 March 28th 07 02:29 PM
Finding last row of every sheet Gwen Excel Programming 10 November 25th 06 10:07 PM
Finding data of one sheet in another sheet don Excel Programming 0 February 18th 06 01:09 AM
Better way of finding last row on sheet Andibevan[_2_] Excel Programming 7 June 16th 05 11:57 PM
Finding last sheet RJH Excel Programming 2 February 22nd 04 04:11 AM


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