Check if a sheet Available vailable in a source workbook Then run code.

AT BABU

Board Regular
Joined
Oct 12, 2018
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hi all

Thank you every one for sharing your knowledge…..

I have small problem need Help
In source workbook
Sheet 1 (Status)
Sheet 2 (resource)
Sheet 3(Summary)
Sheet 4(Support)
Sheet 5 (Support_Details)
Sheet 6 (prime)
Sheet 7(Doc details)
Sheet 8 (New)
I have total 8 Worksheets in source workbook, I need only Sheet 4(Support), Sheet 6 (prime) and Sheet 8 (New)
Problem:
1 In Source Book Sheet 4(Support), Sheet 6 (prime) and Sheet 8 (New), find this sheet are available or not
2 If Sheet find, then run code; if not found sheet go to another work sheet and run code (In 8 Work sheet only this sheets Sheet 4(Support), Sheet 6 (prime) and Sheet 8 (New))


In this Sheets (Sheet 4(Support), Sheet 6 (prime) and Sheet 8 (New)) minimum one sheet available in Socurce Workbook

Sub GetFileCopyData ()
Dim Fname As String
Dim SrcWbk As Workbook (Source workbook)
Dim DestWbk As Workbook (This work book (vba code book))

Set DestWbk = ThisWorkbook

Fname = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*", Title:="Select a File")
If Fname = "False" Then Exit Sub

Set SrcWbk = Workbooks.Open(Fname)

Sheets("Support ").Select

‘’’’’’’’’’’’’’’’’’’ My code’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Sheets("prime ").Select

‘’’’’’’’’’’’’’’’’’’ My code’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Sheets("New ").Select

‘’’’’’’’’’’’’’’’’’’ My code’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi & welcome to MrExcel
How about
Code:
Set SrcWbk = Workbooks.Open(Fname)
If Evaluate("isref('Support '!a1)") Then
   Sheets("Support ").Select

'   ‘’’’’’’’’’’’’’’’’’’ My code’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
End If
 
Upvote 0
Hi Fluff
Thank you for your solution, But Is go to END IF work sheet not select and my code not run
 
Upvote 0
In that case you don't have a sheet called "Support ".
Check that the sheet name is correct, for instance do you have a space after the sheet name?
 
Upvote 0
I changethe Sheet name, we can't changesheet name in above code
In the sourceworkbook I need these three sheet (Sheet4 (Support_Details), Sheet6 (Dummy_prime_Doc details), Sheet8 (Newsupport_Doc_details)),
In sourceworkbook some time given only single sheet, sometime given 2 sheets and also given 3 sheets of in the these three (Sheet4 (Support_Details), Sheet6 (Dummy_prime_Doc details), Sheet8 (Newsupport_Doc_details)),
In these sheet(Sheet4 (Support_Details), Sheet6(Dummy_prime_Docdetails), Sheet8 (New support_Doc_details)), if single sheet available(if 3sheets avilable, if 2sheets available) run code
 
Last edited:
Upvote 0
In that case it needs to be like
Code:
Set SrcWbk = Workbooks.Open(Fname)
If Evaluate("isref('Support_Details'!a1)") Then
   Sheets("Support_Details").Select

'   ‘’’’’’’’’’’’’’’’’’’ My code’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
End If
 
Upvote 0
Thank you so much it Working !!!!
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,465
Members
448,965
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top