+ Reply to Thread
Results 1 to 7 of 7

Out of Subscript error while opening a Userform

Hybrid View

  1. #1
    Registered User
    Join Date
    06-06-2006
    MS-Off Ver
    2010, 365
    Posts
    39

    Out of Subscript error while opening a Userform

    Hi,

    I am getting a "Error '9' : Subscript out of range" error while opening a user form from a button on a sheet. Why is this happening? I checked for typo errors, but there aren't any. What do I do?

    Peace,

    Shivboy

  2. #2
    Piotr Lipski
    Guest

    Re: Out of Subscript error while opening a Userform

    On Wed, 21 Jun 2006 03:09:03 -0500, shivboy wrote:

    > Hi,
    >
    > I am getting a "Error '9' : Subscript out of range" error while opening
    > a user form from a button on a sheet. Why is this happening? I checked
    > for typo errors, but there aren't any. What do I do?


    Paste you code here...

    --
    PL

  3. #3
    NickHK
    Guest

    Re: Out of Subscript error while opening a Userform

    What do you do?
    Don't use a subscript that is out of range, but without any code it's rather
    difficult to advise further.

    NickHK

    "shivboy" <shivboy.29qt2o_1150877403.0454@excelforum-nospam.com> wrote in
    message news:shivboy.29qt2o_1150877403.0454@excelforum-nospam.com...
    >
    > Hi,
    >
    > I am getting a "Error '9' : Subscript out of range" error while opening
    > a user form from a button on a sheet. Why is this happening? I checked
    > for typo errors, but there aren't any. What do I do?
    >
    > Peace,
    >
    > Shivboy
    >
    >
    > --
    > shivboy
    > ------------------------------------------------------------------------
    > shivboy's Profile:

    http://www.excelforum.com/member.php...o&userid=35137
    > View this thread: http://www.excelforum.com/showthread...hreadid=553956
    >




  4. #4
    papou
    Guest

    Re: Out of Subscript error while opening a Userform

    Hello
    Since you don't give much details, I would suggest you check for the
    TakeFocusOnClick property of your button on your worksheet.
    Set this property on False.

    HTH
    Cordially
    Pascal

    "shivboy" <shivboy.29qt2o_1150877403.0454@excelforum-nospam.com> a écrit
    dans le message de news:
    shivboy.29qt2o_1150877403.0454@excelforum-nospam.com...
    >
    > Hi,
    >
    > I am getting a "Error '9' : Subscript out of range" error while opening
    > a user form from a button on a sheet. Why is this happening? I checked
    > for typo errors, but there aren't any. What do I do?
    >
    > Peace,
    >
    > Shivboy
    >
    >
    > --
    > shivboy
    > ------------------------------------------------------------------------
    > shivboy's Profile:
    > http://www.excelforum.com/member.php...o&userid=35137
    > View this thread: http://www.excelforum.com/showthread...hreadid=553956
    >




  5. #5
    Registered User
    Join Date
    06-06-2006
    MS-Off Ver
    2010, 365
    Posts
    39
    Sorry for not posting the code. Here it is:

    Private Sub btnShowiForm_Click()
    newForm.Show
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim stateName() As String
    stateName(0) = "A"
    stateName(1) = "B"
    stateName(2) = "C"
    stateName(3) = "D"
    stateName(4) = "E"
    stateName(5) = "F"
    Dim i As Integer
    With cbSelState
        .Clear
    For i = 0 To UBound(stateName)
        .AddItem (stateName(i))
    Next i
    End With
    End Sub
    Please tell me where I am going wrong. I am somehow not able to figure out the error.

    I tried changing the TakeFocusOnClick property of the button, but still it generated the error.

    Quote Originally Posted by papou
    Hello
    Since you don't give much details, I would suggest you check for the
    TakeFocusOnClick property of your button on your worksheet.
    Set this property on False.

    HTH
    Cordially
    Pascal

    "shivboy" <shivboy.29qt2o_1150877403.0454@excelforum-nospam.com> a écrit
    dans le message de news:
    shivboy.29qt2o_1150877403.0454@excelforum-nospam.com...
    >
    > Hi,
    >
    > I am getting a "Error '9' : Subscript out of range" error while opening
    > a user form from a button on a sheet. Why is this happening? I checked
    > for typo errors, but there aren't any. What do I do?
    >
    > Peace,
    >
    > Shivboy
    >
    >
    > --
    > shivboy
    > ------------------------------------------------------------------------
    > shivboy's Profile:
    > http://www.excelforum.com/member.php...o&userid=35137
    > View this thread: http://www.excelforum.com/showthread...hreadid=553956
    >

  6. #6
    NickHK
    Guest

    Re: Out of Subscript error while opening a Userform

    Well, there you go.
    Your "Dim stateName() As String" creates a dynamic array.
    However it has no elements yet.
    You need to
    Redim stateName(5)
    before you can assign a value to an element.

    Alternatively, it you always need 6 elements (0-5), put that in initial
    declaration:
    Dim stateName(5) As String
    or Dim stateName(0 To 5) As String 'For clarity

    NickHK

    "shivboy" <shivboy.29sdbo_1150950303.7885@excelforum-nospam.com> wrote in
    message news:shivboy.29sdbo_1150950303.7885@excelforum-nospam.com...
    >
    > Sorry for not posting the code. Here it is:
    >
    >
    > Code:
    > --------------------
    >
    > Private Sub btnShowiForm_Click()
    > newForm.Show
    > End Sub
    >
    > Private Sub UserForm_Initialize()
    > Dim stateName() As String
    > stateName(0) = "A"
    > stateName(1) = "B"
    > stateName(2) = "C"
    > stateName(3) = "D"
    > stateName(4) = "E"
    > stateName(5) = "F"
    > Dim i As Integer
    > With cbSelState
    > .Clear
    > For i = 0 To UBound(stateName)
    > .AddItem (stateName(i))
    > Next i
    > End With
    > End Sub
    >
    >
    > --------------------
    >
    >
    > Please tell me where I am going wrong. I am somehow not able to figure
    > out the error.
    >
    > I tried changing the TakeFocusOnClick property of the button, but still
    > it generated the error.
    >
    > papou Wrote:
    > > Hello
    > > Since you don't give much details, I would suggest you check for the
    > > TakeFocusOnClick property of your button on your worksheet.
    > > Set this property on False.
    > >
    > > HTH
    > > Cordially
    > > Pascal
    > >
    > > "shivboy" <shivboy.29qt2o_1150877403.0454@excelforum-nospam.com> a
    > > écrit
    > > dans le message de news:
    > > shivboy.29qt2o_1150877403.0454@excelforum-nospam.com...
    > > >
    > > > Hi,
    > > >
    > > > I am getting a "Error '9' : Subscript out of range" error while

    > > opening
    > > > a user form from a button on a sheet. Why is this happening? I

    > > checked
    > > > for typo errors, but there aren't any. What do I do?
    > > >
    > > > Peace,
    > > >
    > > > Shivboy
    > > >
    > > >
    > > > --
    > > > shivboy
    > > >

    > > ------------------------------------------------------------------------
    > > > shivboy's Profile:
    > > > http://www.excelforum.com/member.php...o&userid=35137
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=553956
    > > >

    >
    >
    > --
    > shivboy
    > ------------------------------------------------------------------------
    > shivboy's Profile:

    http://www.excelforum.com/member.php...o&userid=35137
    > View this thread: http://www.excelforum.com/showthread...hreadid=553956
    >




  7. #7
    Registered User
    Join Date
    06-06-2006
    MS-Off Ver
    2010, 365
    Posts
    39
    Thanks NickHK. That was so stupid of me to have ignore that ! Nevertheless, thank you guys!

    Peace,

    Shivboy

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1