+ Reply to Thread
Results 1 to 14 of 14

Need help to fix the syntax of my code

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Need help to fix the syntax of my code

    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!

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need help to fix the syntax of my code

    maybe something like this

    Form1.Listbox1.RowSource = Sheets(sAllPrecedents).Range("A1:A3")
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    judgeh59, it gave me type mismatch - run time error 13...

  4. #4
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    Just for your info, its defined as this:

    Dim wsAllPrecedents As Worksheet
    Dim sAllPrecedents As String

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need help to fix the syntax of my code

    Is it possible to attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  6. #6
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    Here you go..
    Attached Files Attached Files

  7. #7
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need help to fix the syntax of my code

    I'm not exactly sure what you are trying to do....but this didn't throw an error....

    ufArrows.lbPrecedents.AddItem Sheets(wsAllPrecedents.Name).Cells(ReportRow, 1).Value

  8. #8
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    Thanks judgeh59,

    I pasted the code in the loop and it works fine. Actually I'm trying to get list of precedents and dependents of the cell in the form.

    Thanks for your help!

  9. #9
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need help to fix the syntax of my code

    sweeeeeeeeeeet.....I kind of thought that....glad I could and thanks for the rep points....

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  10. #10
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    Hi judgeh59,

    Wanted one help to tweak the same code. Actually can you get the output for Dependents like the same output I get for Precedents. Both the output differs from each other, I wanted the output just like Precedents for Dependents. Can you get your hands on it? Will be a great help.

    Here is the latest modified version attached.
    Attached Files Attached Files

  11. #11
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need help to fix the syntax of my code

    I assume you are talking about the in the dependent listbox your output is horizontal and vertical on the other?

  12. #12
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    Yes, correct. It should be the same output like we get for precedents. Thanks!

  13. #13
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need help to fix the syntax of my code

    so I made it looks like precedent. That being that there was only 1 dependent. Give it a shot and let me know...Sorry it took so long...
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    09-27-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    97

    Re: Need help to fix the syntax of my code

    Judgeh59, Thanks for your hardwork on this, but this is not the way actually i wanted. I wanted it level wise, as how we get the output of precedents, the same output we want to get in dependents.

    for example:
    [ Level:1] [ Address: [Dependents.xlsm]Sheet1!B7 ]
    [ Level:1] [ Address: [Dependents.xlsm]Sheet1!A7 ]

    Same like this in dependents. It only shows just this in two columns:
    Original Cell.......Dependents
    Sheet1'!C7..........Sheet1'!E7

    You got the idea?

+ 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] code syntax
    By lundy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-14-2014, 01:33 PM
  2. code syntax
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2013, 01:16 AM
  3. [SOLVED] Syntax of VBA Code
    By Ken Hudson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2005, 06:05 PM
  4. Syntax of this code
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2005, 07:06 AM
  5. syntax for code in MsgBox()?
    By Ouka in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2005, 04:05 PM

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