Consulting

Results 1 to 5 of 5

Thread: Help me with syntax of the code...anyone?

  1. #1
    VBAX Regular
    Joined
    Dec 2014
    Posts
    69
    Location

    Help me with syntax of the code...anyone?

    Hi all,


    I'm trying to get the content of cells from a sheet into a listbox in user form. Normally the code goes like this.


    Form1.Listbox1.RowSource = "Sheet1!A1:A3"

    But I'm adding the sheet at the end and and I'm naming it with combining the name of parent sheet. For example, If I'm at Sheet_List, so it adds the sheet to the end like Sheet_List_Pre. So, for this the code goes like this.


    sAllPrecedents = rngToCheck.Parent.Name & "_Pre" 
    Set wsAllPrecedents = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) 
    wsAllPrecedents.Name = sAllPrecedents

    So, my question is how to get the content of this added sheet in listbox. I'm trying something like this, but its giving error.
    Form1.Listbox1.RowSource = sAllPrecedents!A1:A3

    Can someone help me correct the syntax here.


    Thanks!


    Cross-posted here:
    http://www.excelforum.com/showthread...76#post4092076

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Try these and see

    Form1.Listbox1.RowSource = sAllPrecedents & "!A1:A3"

    or

    Form1.Listbox1.RowSource = "'" & sAllPrecedents & "'!A1:A3"
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Dec 2014
    Posts
    69
    Location
    Thanks Paul, first one works fine. Thanks for your help!

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Glad

    Suggest you mark it [Solved] by using ThreadTools at top right

    Come back in new thread if you have additional questions
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Regular
    Joined
    Dec 2014
    Posts
    69
    Location
    Sure. Thanks Paul!

Posting Permissions

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