473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Subscript out of range error 9

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
  26.  
it throws the code at this line
Expand|Select|Wrap|Line Numbers
  1. With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).codemodule
  2.  
any suggestions?
thx,
Rodney
Nov 2 '11 #1
1 2341
Killer42
8,435 Expert 8TB
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

2
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...
2
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...
2
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 ==...
8
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...
2
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...
4
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 =...
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 9.5.0.7 on a Windows...
6
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...
1
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....
1
banning
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 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.