Question:
VBA Code - Run-time Error 9?
Lilah
2011-04-01 13:05:41 UTC
Can anyone please tell me why the following code gives me a "Run-time error 9: Subscript out of range"?

Sub GoToJaxEnergyData()
' GoToJaxEnergyData Macro
If ActiveSheet.Name <> "Jax_Energy" Then
Sheets("Jax_Energy").Visible = -1
ActiveSheet.Visible = 2
End If
End Sub

All the other codes for other cities work perfectly. This is the only one that's giving me a headache. I can't figure it out and it's driving me crazy. Please help me.
Eleven answers:
garbo7441
2011-04-01 14:16:09 UTC
The error message you are receiving indicates that Excel thinks there is no sheet named "Jax_Energy".



The most common thing that would cause this is if there is a 'space' at the beginning or end of the sheet name. You would not necessarily notice this just looking at the sheet tab.



Try renaming the sheet exactly "Jax_Energy"



The 'space' character could also be in your line of code. Excel considers a 'space' to be a valid character, just as 'A', '3', '!', etc are.
?
2016-09-28 15:56:12 UTC
Run Time Error 9
?
2016-05-02 11:39:05 UTC
I am a professional developer with Microsoft, and have about 10 years of experience in the field of Computer Engineering. Most problems with PC's are the result of malicious software that infected a Computer. Examples of this are things such as malware, viruses, trojans, spyware, adware, root kits, and worms. In other cases, they are the result of stability issues due to crashes, freezes, or Hardware Issues. Some examples of hardware issues could be a dirty cooling fan causing the computer to overheat, or low memory due to lack of RAM, which could cause the PC to run slowly. You may think it could be a virus, or malware, or registry issues, but it could be something else entirely. As a computer layman, one may find it hard to really ascertain what exactly is causing the problems, without having a professional do an in depth analysis of your PC.



As professional computer repairs can be quite costly, I would recommend to you a Software that many of us in the tech department here at Microsoft use personally and professionally to diagnose and repair computer problems very quickly. It is a software called Reimage, from https://tr.im/ReimageRepair .. In my personal experience, and in the experience of many of my associates, this is probably the best software ever created for those experiencing computer troubles. This is likely to remedy just about ANY problem your computer could possibly be having, and have it running like new. Reimage has won several awards, and been featured in publications such as PC Mag.
almaraz
2016-12-11 15:40:29 UTC
Subscript Out Of Range Excel
?
2011-04-01 13:16:16 UTC
Does the VB environment stop with a particular line highlighted in yellow? Or can you figure out from context (a subscript reference) which line the message would refer to?



The only line I see is that reference to



Sheets("Jax_Energy").Visible = -1



Are you sure there was such an entry in Sheets when that code was about to be executed? Prove it.



I'd put a breakpoint in the code and examine sheets() just before the Runtime error takes hold.



Hope that helps.
Lula
2015-08-07 13:49:42 UTC
This Site Might Help You.



RE:

VBA Code - Run-time Error 9?

Can anyone please tell me why the following code gives me a "Run-time error 9: Subscript out of range"?



Sub GoToJaxEnergyData()

' GoToJaxEnergyData Macro

If ActiveSheet.Name <> "Jax_Energy" Then

Sheets("Jax_Energy").Visible = -1

ActiveSheet.Visible...
anonymous
2014-09-03 18:11:30 UTC
Don't listen to these guys, they clearly have no clue on what they're talking about. I am a developer at Microsoft so I know a thing or two about computers. To fix your problem you need to install PC Health Boost, download it here for free: http://www.healthboostpc.com



It's very light and it's the only antivirus/cleaner with a 99.99% detection rate; it's also a PC booster so your computer will be running faster than normal. Install it, hit run and problem solved. It shouldn't take you more than 5 minutes.
AJ
2011-04-01 13:26:07 UTC
Ok this macro is doing much more than just going to the Jax Energy sheet.



So based on your code, you are assuming that this Jax_Energy sheet is hidden then you hide the active sheet, yet at no time are you actually selecting the Jax_Energy sheet and making it the active sheet.



I mean you don't even need an if statement.



Just do



Sheets("Jax_Energy").Select



It that simple. Don't know why you would want to complete hide just 1 sheet.
anonymous
2015-01-27 04:09:06 UTC
Hello. My name is Sanjay Patel, and I currently hold an honorary Master's degree in the field of Computer Science. I am aware of, and have personal knowledge related to your question. There are computer maintenance businesses which are probably in your area, however they come at the cost of hiring a professional to enter your home. There may also be some local destinations where you can drop off your computer and wait to have a technician look at it. These options can often be costly, and pretty inconvenient. The answer to this question can probably be found doing a little extra research on Google.



A well-running computer can be a hard thing to maintain. From my experience, there is but only One software which is reputable- and consistently reliable for healing sick, slow computers. Reimageā„¢ - https://reimagefix.im is a world-renown, easy to use software designed by Forensic scientists and made for the average person. This thing will fix literally just about ANY problem you could possibly be having with your PC. Reimage was recommended to me by a Professor during my 2nd year of Graduate school
cassey
2015-01-28 06:28:02 UTC
I just tried https://reimagefix.im mentioned by that Sanjay guy on here and it completely fixed my computer. I was having all kinds of problems that were absolutely annoying me to death. This computer had viruses, spyware, error messages, hardware problems, and it would often crash or freeze on me. I think the worst thing to me was how SLOW and laggy it became. So just when I was about to wash my hands with it, and waste money on a new computer...I find this.
?
2016-02-23 20:06:08 UTC
See -- https://reimagefix.im


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...