Results 1 to 9 of 9

Variable not defined error

Threaded View

  1. #1
    Registered User
    Join Date
    12-05-2010
    Location
    LA, CA
    MS-Off Ver
    Excel 2010
    Posts
    59

    Variable not defined error

    Hi,
    I copied code from another sheet into my own and I keep getting a variable not defined on "Listbox1" I'm not sure why. Can someone help me? Here is the code:

    Option Explicit
    
    Dim rg As Range
    Private Sub Worksheet_Activate()
       Set rg = Sheets(1).Range("A6:A25")      '<< Update Here : Range with list names
       ' OR
       'Set rg = Sheets(1).Range("A6:A" & Sheets(1).Range("A" & Rows.Count).End(xlUp).Row)     'dynamic range
    End Sub
    
    Sub PopulateListBox()
       Dim ar, i As Integer
       
       Application.ScreenUpdating = False
       
       If rg Is Nothing Then Worksheet_Activate
       
       rg.EntireRow.Hidden = False      'By default all series are visible
       ar = rg.Value
       With ListBox1
          .List = ar
          For i = 0 To .ListCount - 1
              .Selected(i) = True
          Next i
       End With
    
       Application.DisplayAlerts = True
    End Sub
    
    Private Sub ListBox_Mouseup(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    'When listbox is clicked, refresh series
       Dim i As Integer
       Application.ScreenUpdating = False
       With ListBox1
          For i = 0 To .ListCount - 1
             rg.Offset(i).EntireRow.Hidden = Not .Selected(i)
             Debug.Print i; .Selected(i)
          Next i
       End With
       Application.ScreenUpdating = True
    End Sub
    Last edited by janeml; 07-07-2013 at 07:36 PM.

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