473,563 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subscript out of range error 9

61 New Member
This is a wierd issue that i'm having. When I run the code without having vba open I get the error 9 message, but when I open vba and run the code it runs just fine. Here is the code

Expand|Select|Wrap|Line Numbers
  1. Public Sub preformat()
  2. 'Application.ScreenUpdating = False
  3.     Workbooks.Add
  4.     Do
  5.         If InStr(1, ActiveWorkbook.Name, "Book") > 0 Then Exit Do
  6.         ActiveWindow.ActivateNext
  7.     Loop
  8.     Columns("B:B").NumberFormat = "@"
  9.     Columns("D:E").NumberFormat = "0.000"
  10.     Columns("H:J").HorizontalAlignment = xlCenter
  11.     Range("A1").Select
  12.     'This procedure sets up the workbook procedure
  13. With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).codemodule
  14.     'Add the empty procedure
  15.     .InsertLines 1, "Private Sub Worksheet_SelectionChange(ByVal target As Range)"
  16.     .InsertLines 2, "If Target.Column < 8 Or Target.Column > 10 then Exit Sub"
  17.     .InsertLines 3, "If ActiveCell = """" Then"
  18.     .InsertLines 4, vbTab & "ActiveCell = ""X"""
  19.     .InsertLines 5, "ElseIf ActiveCell = ""X"" Then"
  20.     .InsertLines 6, vbTab & "ActiveCell = """
  21.     .InsertLines 7, "End If"
  22.     .InsertLines 8, "End Sub"
  23. End With
  24. 'Application.ScreenUpdating = True
  25. End Sub
it throws the code at this line
Expand|Select|Wrap|Line Numbers
  1. With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).codemodule
any suggestions?
Nov 2 '11 #1
1 2344
8,435 Recognized Expert Expert
I'd recommend you copy and paste this question into the Access / VBA forum where you'll find a lot more VBA expertise.
Dec 18 '11 #2

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

Similar topics

by: Lukelrc | last post by:
Hi, I have some VBscript that lists the files in a folder. What i want to do is populate an array with the file names and then use that array to populate a list box. I have got as far as populating the array, but i can't get rid of the error 'Subscript Out Of Range' Can anyone see where i have gone wrong? <script language = vbscript...
by: jv | last post by:
I have a form that is used every day to create quotes. However, every 2 weeks or so a user would randomly get an error 9 - subscript out range message. I'm not using any array in this form. Does anyone know that else might possibly trigger this error besides array? Thanks Julie
by: kscdavefl | last post by:
When I run the following code: private void applicationPermissionGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item || (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.AlternatingItem)) {
by: VB Programmer | last post by:
I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for version 6.... I need help for something that should be simple. I keep getting a "subscript out of range" error and don't know why. Briefly.... I have an array of Variants dimmed as this: Global gMyConnection() As Variant I redim it later like this:
by: Henry J. | last post by:
Has anybody run into this index out range exception when opening and then closing a collectionEditor from within a PropertyGrid? I use PropertyGrid to edit configurations in my application. One of the fields is a collection. I can expand or collapse the collection in the PropertyGrid fine. However,if I open the CollectionEditor...
by: Sheldon | last post by:
Hi, I have a written a script that will check to see if the divisor is zero before executing but python will not allow this: if statistic_array > 0.0: statistic_array = int(multiply(divide(statistic_array,statistic_array \ ),10000.0))/100.0
by: dalaeth | last post by:
I have searched Google high and low and haven't found anything that works. Here's my problem, hopefully someone will be able to help! I'm using 1.1 Framework, and ODP.NET on a Windows 2003 Server. I have a cached DataSet that I fill using an OracleDataAdapter. Changes are made to that dataset in memory and as rows are changed,...
by: bloukopkoggelmander | last post by:
Hi all. I use Access 2007. I have linked tables set up to a AS400 server. When I try to split the database, I get the following error : Subscript out of range. I have no idea what this mean. I have googled it, but not much clearer on this. Any idea anyone?
by: fperri | last post by:
I have converted a database I finished into an MDE. I'm supposed to be delivering it today. I get a subscript out of range error when the user tries to print a report from the print preview window. If the report is printed via code, I do not get this error. It tells me it is the onFormat event that is causing the error but in my regular database...
by: banning | last post by:
Im a PHP developer and I officially HATE ASP why does my code give me this error? ERROR: "Microsoft VBScript runtime error '800a0009' Subscript out of range /synergy/docs/ProductionReports.asp, line 42 "
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...
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...
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. ...
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...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
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...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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...

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.