Results 1 to 2 of 2

Thread: Dynamic table based on userform selection

  1. #1

    Dynamic table based on userform selection


    I am trying to add/delete rows to an existing table in the document based on user selection in the userform. I have the code working to add rows below the header row based on a _change event, but I am not able to figure out how to delete rows if the user selects for example "4" and then changes the combo box to "7". This will cause 11 rows to be added when only 7 are needed. I could probably assign the add rows to the cmdButton_click, but then if they reopened the userform and changed the selection I would still have the same problem.

    Any help would be appreciated or if someone could point me in the right direction if this solution exists elsewhere that I haven't been able to find.

    Public Sub cbArraySize_Change()
    If cbArraySize.Value <> 0 Then
    DeleteRows '<---- This Sub I haven't figured out.
    End If
    End Sub
    Sub AddRows()
    With ActiveDocument
    Selection.InsertRowsBelow (cbArraySize.Value)
    End With
    End Sub

  2. #2
    Start with the table each time with only the core rows, i.e. before adding the rows, delete the previously added rows. You will then only have the number of rows defined in your array.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

Posting Permissions

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