Results 1 to 3 of 3

Thread: Splitting a particluar column into multiple rows

  1. #1
    VBAX Newbie
    Jun 2023

    Splitting a particluar column into multiple rows

    I'm brand new to VBA, but have coded in VB before.
    In Microsoft Word, starting with a table of 33 rows and 3 columns, I want to split each of the initial 33 rows (of column 3 only) into 10 rows each.
    I thought this would be pretty easy, but the code (below) doesn't work. It actually works for the first 2 (of the original) rows, but then the count somehow gets messed up and the third original row doesn't work. I'm not sure why (the count will continue to increase as I am adding 10 rows at a time). As well, the routine ends with no error messages and the job is not complete (except for the first two original rows).

    The code I'm using:

    Sub SplitColumnIntoRows()
    ' In Microsoft Word, split each of the initial 33 rows (of column 3 only) into 10 rows each.
    Dim tbl As Table
        Dim row As Integer
        Dim rowCount As Integer
        Dim col As Integer
    ' Set the table reference to my specific table
        Set tbl = ActiveDocument.Tables(1)
    ' Loop through the appropriate cell in the table (column 3 only)
        col = 3
    rowCount = tbl.Columns(col).Cells.Count
    For row = 1 To rowCount Step 10
    tbl.cell(row, col).Select
    ' Split cell into desired number of rows
            Selection.Cells.Split NumRows:=10, NumColumns:=1
            rowCount = tbl.Columns(col).Cells.Count
    End Sub
    Any illumination would be helpful.
    Thank you in advance.
    Last edited by Aussiebear; 06-10-2023 at 12:14 AM. Reason: Added code tags

  2. #2
    Moderator VBAX Guru Aussiebear's Avatar
    Dec 2005
    Welcome VBAX MCS. Please be patient as hopefully a word guru will be along shortly.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Sep 2005
    So at the end of the show, you are going to have a table with 330 rows:
    Sub SplitColumnIntoRows()
    Dim oTbl As Table
    Dim lngRow As Long
       Set oTbl = ActiveDocument.Tables(1)
       For lngRow = 1 To 330 Step 10
          oTbl.Cell(lngRow, 3).Select
          Selection.Cells(1).Split NumRows:=10, NumColumns:=1
       Next lngRow
      Exit Sub
    End Sub

    Visit my website:

Tags for this Thread

Posting Permissions

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