+ Reply to Thread
Results 1 to 5 of 5

Combobox addition to Rowsource in dynamic named range corrupting table

Hybrid View

BFD Combobox addition to... 08-10-2014, 08:44 PM
millz Re: Combobox addition to... 08-10-2014, 09:28 PM
BFD Re: Combobox addition to... 08-10-2014, 10:28 PM
millz Re: Combobox addition to... 08-10-2014, 10:41 PM
BFD Re: Combobox addition to... 08-10-2014, 11:03 PM
  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    3

    Combobox addition to Rowsource in dynamic named range corrupting table

    I thought I was fairly proficient in VBA but this has me stumped and has cost many many hours without a solution, hence request for help.

    my Userform with combobox entries for product checks against the rowsource and if not on the list, is added to the list. the list is a named range in a Table that is used in a data model.

    No matter which way I try I am regularly getting a corruption in the table that is home to the named range which is the rowsource... after one or two entries from the userform.

    The rowsource is not bound to the worksheet, it is populated at userform_initialize procedure.
    (There are 4 combobox drawing from same rouwsource hence the loop through to check each)

    debug points to the line at which conbobox value is being entered into the rowsource, though not always - it sometimes just crashes the whole file and everything needs restarting, upon which the table is fine and entry is evident.

    I have tried resize, addrow to bottom of table variations and all result in the same core problem of a table corruption that crashes the file.

    I am totally stumped and out of ideas. any help appreciated

    Private Sub CommandButton1_Click()
        
        Application.EnableEvents = False
        
        Dim cCont As Control
        Dim sourcedata As Range, NxtEmptyRow As Long
        Dim found As Object
        Dim ws As Worksheet
        Dim Result As Variant
        Dim Tble As ListObject
        
        Set ws = Worksheets("ProductInfo")
        Set sourcedata = ws.Range("SprayProductName")
            
           For Each cCont In Me.FrameRecommendations.Controls
    
    On Error Resume Next
    
            If TypeName(cCont) = "ComboBox" Then
                  NxtEmptyRow = ws.Range("T3").End(xlDown).Row + 1
                  Set found = Nothing
                    'Set cCont = Product1Rec                         '1
                    Set found = sourcedata.Find(cCont.Value)
                
                    If found Is Nothing Then
                        
                    Set Result = cCont
                    
                    ws.Cells(NxtEmptyRow, 20) = Result  
    
                    cCont.RowSource = Range("SprayProductName").Address(external:=True)
                    
                                    
                    End If
            End If
    
         Next cCont
        Application.EnableEvents = True
        Exit Sub
           
    errHandler:
    MsgBox Err.Description
    
    End Sub
    the sub to initialize the rowsource (and the rest of the userform) is below

    Private Sub SprayRecEntryForm_Initialize()
    'empty all Control Boxes and list box with Clear command box
        Product1rec.RowSource = Range("SprayProductName").Address(external:=True)
        Product2rec.RowSource = Range("SprayProductName").Address(external:=True)
        Product3rec.RowSource = Range("SprayProductName").Address(external:=True)
        Product4rec.RowSource = Range("SprayProductName").Address(external:=True)
     
    more code below but cut for brevity


    thanks

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Combobox addition to Rowsource in dynamic named range corrupting table

    Have you tried table's DataBodyRange instead of a named range?

    ws.ListObjects("YourTableName").DataBodyRange.Address  ' <-- If only a specific column is needed then add .Columns(1) before .Address
    Also, when adding a new item that is not on the list to the table, you should not use the "Set" command. Not that you can't, but you are actually setting "Result" to the combo box object itself.

    Set Result = cCont  ' <-- remove
    ws.Cells(NxtEmptyRow, 20).Value = cCont.Value
    I don't know if these would help your problems, just suggesting some ideas.
    多么想要告诉你 我好喜欢你

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    3

    Re: Combobox addition to Rowsource in dynamic named range corrupting table

    Thanks Millz,
    - I know the .listobjects("table").databodyrange.listcolumns(1).address should work but it aint. giving on Object error. code is running using the named range instead without a hitch until somewhere after the problem kicks in

    - changed the ...=ccont.value as per your suggestion and am getting the result I want which is value placed in appropriate place in the named range

    ... But am still getting the same problem with table corrupting and excel crashing i'm afraid

    Have gone back to an earlier version of the file, ie corruption free, replaced code and retried and getting the same problem result

    it doesn't appear to be a problem with the code, per se, as it does what is asked but somehow it is conflicting with rowsource because the table is definitely corrupting.

    If I remove the Table and just have a range, there is no problem... but the table is needed for powerpivot relationships

    any other ideas appreciated. thanks

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Combobox addition to Rowsource in dynamic named range corrupting table

    Hi BFD, DataBodyRange returns a Range object, of which there is no ".listcolumn" method/property, it should be just ".columns". But then again, not sure if that's exactly the problem causing the crash. Did you try recreating the table?

  5. #5
    Registered User
    Join Date
    07-16-2014
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    3

    Re: Combobox addition to Rowsource in dynamic named range corrupting table

    Thanks for .columns v .listcolumns reminder
    Still crashing and yes, have tried recreating the table a couple of times to no avail as yet.

    Perhaps better to keep the rowsource and table separate to avoid the problem and link rowsouce range to the table some other way. Not elegant solution but may remove the problem

+ 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] Populating ComboBox using dynamic named range - Error
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2014, 05:42 AM
  2. activex combobox and dynamic named range
    By lcsw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2013, 05:30 PM
  3. [SOLVED] combobox dynamic rowsource
    By rybussell in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-27-2013, 01:56 AM
  4. Combobox Rowsource Dynamic Range
    By roy__lam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2012, 09:44 AM
  5. Setting ComboBox.RowSource via Named Range
    By RobertL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2007, 08:19 PM

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