none
Identify when the table cell has multiple paragraphs RRS feed

  • Question

  • Hello All,

    My document has 3 columns table with maximum 4 rows including table caption.

    I am checking for a macro to identify If any of the cell in a specified table has more than one paragraph, the macro should specify the column number only for this specified table. 

    Example table: In the below table column 1 & 3 have more than 1 paragraph. 

    My document has more number of similar tables and all the tables have the same table caption.

    Title of each class

    Shares/

    Warrants type

    Date of redeemed

    Debentures, $0.021 par value per each

    Authorized Shares, $0.001 par value per share Debentures, $0.021 par value per each

    Redeemable prior to acquisition

    15<sup>th</sup> August 2020

    03<sup>rd</sup> February 2021

    -----------------------

    Nakul


    Friday, November 8, 2019 6:16 AM

Answers

  • Hi Nakul,

    This is a sample: When the number of paragraphs in each cell is more than one, it shows Table, Row, Column, and the number of paragraphs. 
    ' --- count the number of paragraphs in each cell
    Sub Count_Paragraph()
      Dim tbl As Table
      Dim tblNo As Integer: tblNo = 0
      Dim rowCnt, colCnt As Integer
      Dim currentCell As Range
      Dim charCnt As Integer
      Dim cellText As String
      Dim paragraphCnt As Integer: paragraphCnt = 0
      ' ---
      For Each tbl In ThisDocument.Tables
        tblNo = tblNo + 1
        ' --- MsgBox "Table Count = " & tblNo
        With ThisDocument.Tables(tblNo)
          For rowCnt = 1 To .Rows.Count
            For colCnt = 1 To .Columns.Count
              ' --- count the number of characters
              cellText = .Cell(rowCnt, colCnt).Range.Text
              charCnt = Len(cellText)
              ' --- count the number of paragraphs
              Set currentCell = .Cell(rowCnt, colCnt).Range
              paragraphCnt = currentCell.Paragraphs.Count
              ' ---
              If (paragraphCnt > 1) Then
                MsgBox "Table [" & tblNo & "] " & vbCrLf _
                  & "Row: " & rowCnt & ", Column: " & colCnt & vbCrLf _
                  & "characters = " & charCnt & vbCrLf _
                  & "paragraph  = " & paragraphCnt
              End If
            Next colCnt
          Next rowCnt
        End With
      Next
      ' ---
      MsgBox "[Count_Paragraph] completed !!"
    End Sub
    P.S.
      I've shared my sample "Nakul_Table.docm" via OneDrive.
      Please download it and check if it works.

    Regards,

    Ashidacchi -- http://hokusosha.com


    • Edited by Ashidacchi Friday, November 8, 2019 8:37 AM shared a sample
    • Marked as answer by Nakul1986 Friday, November 8, 2019 9:23 AM
    Friday, November 8, 2019 8:31 AM