Search : in
By :

VBA: Error 9; subscript is out of reach

Last answer on Jul 16, 2009 4:51:53 pm BST Trowa, on Jul 14, 2009 2:08:03 pm BST 
 Report this message to moderators

Hello,

Depending on the value of a specific cell (sheet "gegevensblad" cell L10), I would like to hide 1 out of 2 sheets (Either Overzichtsgrafieken 1 or Overzichtgrafieken 2).

The value in cell L10 can be either "Ja" or "Nee".
If value is "Ja" then hide sheet "Overzichtsgrafieken 1"
Else hide sheet "Overzichtsgrafieken 2" (or: if value is "Nee" then hide sheet "Overzichtsgrafieken 2")

I have come up with the following code:
Sub HideGraphicSheet()
If Sheets("Gegevensblad").Range("L10") = Ja Then Sheets("Overzichtsgrafieken 1").Visible = False Else Sheets("Overzichtsgrafieken 2").Visible = False
End Sub

(in VBA the code from "If sheets" till "= False" is on one line)

When running the code it gives error 9: subscript is out of reach. The part after Else is coated in yellow.

What am I doing wrong?
Can anyone provide me with a code that works?

Thanks in advance,
Trowa

Configuration: Windows 2003 Internet Explorer 7.0

Best answers for « VBA: Error 9; subscript is out of reach » in :
[Playstation 3] Unable to connect: DNS Error Show [Playstation 3] Unable to connect: DNS Error How to restore a connection problem for your PS3 In most cases, simply go to the Settings Network Settings/Test internet connection. Testing your connection (if it is fully configured in...
[Debian] Apt-get : NO_PUBKEY / GPG error Show[Debian] Apt-get : NO_PUBKEY / GPG error When updating the Debian based system, it may happens that the apt-get displays an error message like: W: GPG error: ftp://ftp.debian.org/ testing Release: The following signatures couldn't be...
Error Connection (80048820) ShowError Connection (80048820) Solutions Before any configuration on your system, it is recommended that you check the status of MSN Messenger servers to determine if the problem does not come from there:...
Error Codes in Windows ShowError Codes in Windows The list below details the error codes displayed in the dialog boxes in Windows: Code Description _________________________________________________________________________ 1 Incorrect function....
Error checking ShowError checking Binary encoding is very practical for use in electronic devices such as computers, in which information can be encoded based on whether an electrical signal is present or not. However, this electrical signal may suffer disturbances...

1

Dean, on Jul 14, 2009 2:38:25 pm BST
  • +1

Noticed this and I think I can help. Your trying to read a sheet that is not there or your not calling it correctly. Say your reading Sheet 3 which is 2 in the sheets collection, or check the spelling.

send a sinpit of code if you cannot get it form here
Dean

Reply to Dean

2

Dean, on Jul 14, 2009 3:03:57 pm BST
  • +1

If Sheets("Sheet1").Range("A1") = "JA" Then Sheets(1).Visible = False '"Sheet2" is Sheets(1)

This works for me, I did notice that your JA is not in Quotes

Please dbl check your Sheet ref.

Dean

Reply to Dean

3

Trowa, on Jul 16, 2009 11:21:06 am BST

Thanks Dean,

Both comments were spot on: I forgot the quotes (thought they were not necessary) and made a typo in one of the sheets name.

Thanks again,
Trowa

Reply to Trowa

4

 Dean, on Jul 16, 2009 4:51:53 pm BST

No problem, your welcome
Dean

Reply to Dean