+ Reply to Thread
Results 1 to 2 of 2

Listbox needs referencing to correct Worksheet

  1. #1
    Registered User
    Join Date
    04-01-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    4

    Listbox needs referencing to correct Worksheet

    Hi Guys,

    I have a problem with my Listbox that it only references the correct worksheet (Sheet2) when that worksheet is active. Can someone help me code the following that it references the correct worksheet.

    Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim j As Integer

    ListBox2.RowSource = ""

    j = 0

    For i = 2 To Range("B65536").End(xlUp).Row
    If ComboBox2.Text = Cells(i, 3) Then
    With ListBox2
    .AddItem
    .List(j, 0) = Cells(i, 2)
    .List(j, 1) = Cells(i, 3)
    .List(j, 2) = Cells(i, 4)
    .List(j, 3) = Cells(i, 5)
    .List(j, 4) = Cells(i, 6)
    .List(j, 5) = Cells(i, 7)
    .List(j, 6) = Cells(i, 8)
    .List(j, 7) = Cells(i, 9)
    End With
    j = j + 1
    End If
    Next i

    End Sub
    Private Sub UserForm_Initialize()
    With Me.ListBox2
    .ColumnCount = 8
    .ColumnWidths = "100;128;60;60;60;60;60;60"
    .RowSource = Sheet9.Range("B2:I600").Address
    End With
    End Sub

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Listbox needs referencing to correct Worksheet

    Please wrap your code with code tags as per forum's rule.
    If you have not referenced a sheet, by default the code works on the active(Where ever the cursor is)

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Correct syntax for referencing a separate worksheet in a formula when.
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2014, 03:01 PM
  2. [SOLVED] Sorting Listbox numerically correct
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2014, 08:38 AM
  3. [SOLVED] Correct Syntax for Listbox Dates
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2012, 04:20 AM
  4. How to set listbox inside excel in the correct way?
    By toplisek in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2012, 05:30 AM
  5. How to set Listbox for coloumns in correct way
    By toplisek in forum Excel General
    Replies: 0
    Last Post: 01-06-2012, 10:44 AM

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