473,657 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Run-time error '9': when trying to open workbook and delete all sheets but 1

1 New Member
I'm trying to delete sheets 1,2,4,5 and make sheet 3 the active one. I get the error on " Sheets(1).Selec t" and "Sheets(Array(1 , 2, 4, 5)).Select". I get a run time error when I try and run the following macro. Help?


zFolder = zPath & "\Kitty*"
Application.Dis playAlerts = False
Sheets(1).Selec t
ActiveWindow.Sc rollWorkbookTab s Position:=xlFir st
ActiveWindow.Sc rollWorkbookTab s Position:=xlFir st
Sheets(Array(1, 2, 4, 5)).Select
Sheets(1).Activ ate
ActiveWindow.Se lectedSheets.De lete
On Error Resume Next
Sheets("regress ").Delete
On Error GoTo 0
Application.Dis playAlerts = True
Aug 12 '09 #1
1 2566
MikeTheBike
639 Recognized Expert Contributor
@grippy10
Hi

I have more questions than answers, but this will do what you have described.
Expand|Select|Wrap|Line Numbers
  1. Sub DeleteActiveBookSheetsExceptSheet3()
  2.     Dim i As Integer
  3.     Application.DisplayAlerts = False
  4.         With ActiveWorkbook
  5.             For i = .Sheets.Count To 1 Step -1
  6.                 If i <> 3 And .Sheets.Count > 1 Then .Sheets(i).Delete
  7.             Next i
  8.         End With
  9.     Application.DisplayAlerts = True
  10. End Sub
With some mods you can probably bend it to suit your requirements!!


MTB
Aug 17 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1510
by: Allan Topp | last post by:
I know little to nothing about PHP and need to clarify something before committing to learning it. From what I have heard PHP would be ideal to interrogate a database and populate HTML tables with found data (text AND URL's). However, what I want to do is to have the files on a CD rather than a web site. One colleague assures me that having PHP run on my machine is not a problem.
5
5773
by: Toby Donaldson | last post by:
Hi all, I'm designing an educational application that will run Python code and check the output against a pre-define answer. I want to use the "exec" statement to run the code, but I don't know how to get output from it. For instance, exec works like this: >>> code = """ for i in xrange(1, 5):
1
3383
by: John H. | last post by:
I installed the Microsoft Script Debugger and set the "Enable Script Debug" flag on in IIS. Also, I made sure that the "Disable Script Debug" flag was off in Internet Explorer. Everything ran fine for about two months; the Debugger was getting control. Then, all of a sudden, it has stopped getting control. I checked the settings above and they still OK. Anybody can tell me why the Debugger is not getting control? Should I report this...
1
3889
by: Oleg Shnayderman | last post by:
Hi All, I am very new to C# as well as to SQL. I need to write an application which is connecting to SQL DB and getting all the user's tables and after create a dataset for all the tables in the database and create an XML document with all the info. The problem is, that I can do this if I know the table name. However, what if I don't know the table name nor I know how many user's tables in the particular database.
6
2177
by: Jack Duijf | last post by:
Hello, I am looking for a person in The Netherlands that is willing to help me getting started with Vb.net. Please send a message to jack@aicn.nl if you can help me getting started with the Microsoft Developement Enviroment. Thanks,
2
6943
by: ¹é¿ø¼® | last post by:
Hello, everybody. I want to call any shell command from php script using shell_exec(). The problem is that the next line of the php script would not be run until a few minutes after running the shell command. I found the shell command couldn't be run at background mode. It seemed that the shell_exec() function waits a return from the command. Because the command doesn't return, the shell_exec() waits until timeout reached. Using the '&'...
13
1761
by: ThaDoctor | last post by:
I would like to get started with programming in C, but I cant get it to work, I do not need any compiler or such. Only a basic explanation of the first program Hello World that print "Hello World" on the screen. Greetings Tobias
6
10990
by: DRS.Usenet | last post by:
When I run alert("page contents:" + content.document.documentElement.innerHTML); I am able to pull the content. I see something like this page contents:<head><title>A Title</title> <FRAMESET ROWS="75,*">
1
1773
by: sbettadpur | last post by:
hello i am calling .exe file through my php script. i.e. using exec or system command, i am running exe file that exe file will create on txt file which contains who has logged into domain(i.e. domain user name). actually once i run exe file the generated file name is according to user itself for eg if "xyz" is a domain user who logged into domain and if he access the php script (remember php script is calling exe file) the final...
4
1677
by: tkpmep | last post by:
I've just bought an iMac (OS X 10.5.2, will almost immediately jump to 10.5.3), and am looking to install Python on it, and to use it with XCode, Apple's IDE. Some googling suggests that a number of people have had trouble getting Python to run satisfactorily on their Macs. This is my first Mac, and I'd appreciate some guidance on what to do (and what not to) when installing Python and potential problems to keep an eye open for. I want to...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.