+ Reply to Thread
Results 1 to 6 of 6

Assign a range of a Worksheet type variable to SourceRow of ListBox

  1. #1
    Registered User
    Join Date
    10-15-2019
    Location
    Puerto Rico
    MS-Off Ver
    2016
    Posts
    3

    Assign a range of a Worksheet type variable to SourceRow of ListBox

    Hello there,
    I am trying to assign a range of cells that is the same in all the Worksheets. I already created a Worksheet type variable called "sht" that was declared in the "CycleTimeApp" Userform, but
    the "Run-time error '91': Object Variable or With block variable not set" was showed. I share the part of the code with the problem:

    Private Sub UserForm_Initialize()

    ListBox1.RowSource = CycleTimeApp.sht.Range("W2:W42").Address

    End Sub

    I'll appreciate any help.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Assign a range of a Worksheet type variable to SourceRow of ListBox

    Not enough info:
    So you:
    Dim sht as worksheet?
    Did you Set sht = sheets("?") ...?

    Next:
    ListBox1.List = sht.Range("W2:W42").Value
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-15-2019
    Location
    Puerto Rico
    MS-Off Ver
    2016
    Posts
    3

    Re: Assign a range of a Worksheet type variable to SourceRow of ListBox

    Thanks ProtonLeah,
    It didn't worked, I tried different ways. Right now, I am trying to do the same thing but simpler. The RowSource in the ComboBox properties is blank

    The following is the Macro running in a module:

    Please Login or Register  to view this content.
    Public Sub EquipmentSel()
    If HomeScreen.ComboBox1.Value = "Text1" Then
    CycleTimeApp.ComboBox1.RowSource = Sheets(1).Range("B4:B12").Address
    End If
    End Sub
    Please Login or Register  to view this content.


    Using .List the Run-time error '70: Permission denied pops up, the Debug sent me to:

    Please Login or Register  to view this content.
    CycleTimeApp.ComboBox1.List = Sheets(1).Range("B4:B12").Value.
    Please Login or Register  to view this content.


    Now I decided to do it with .RowSource, the code doesn't return any error this time, however the ComboBox is empty.

    Could you, please help me with that matter?

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Assign a range of a Worksheet type variable to SourceRow of ListBox

    You should include the sheet name:

    Please Login or Register  to view this content.
    Rory

  5. #5
    Registered User
    Join Date
    10-15-2019
    Location
    Puerto Rico
    MS-Off Ver
    2016
    Posts
    3

    Re: Assign a range of a Worksheet type variable to SourceRow of ListBox

    Great!! Spectacular
    Thank you very much for your help!!!!

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Assign a range of a Worksheet type variable to SourceRow of ListBox

    Glad to help, and thanks for the rep.

+ 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] User defined type: assign a variable to another variable
    By BNCOXUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2019, 10:51 AM
  2. How to Assign Variable Name to Worksheet Object Using Its Code Name
    By Merf in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-02-2015, 03:27 PM
  3. Trying to assign ListBox to object variable, but getting listbox value
    By JEA_123 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-12-2015, 05:45 AM
  4. Assign and found range to a variable
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2009, 10:55 AM
  5. How to assign an imported XML worksheet range to a VBA variable?
    By tonybreyal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2009, 02:34 PM
  6. Assign a worksheet name to a variable
    By benjammind in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2005, 06:16 AM
  7. Add new worksheet and assign it to an object variable?
    By Thief_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2005, 03:06 AM

Tags for this Thread

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