Solved How to get the number of columns (or cells) in current row

Capitala

Member
Local time
Today, 14:03
Joined
Oct 21, 2021
Messages
73
Good day!
I need a vba code to get the number of columns or cells in current (selected) row in MS word.
NB: the number of cells are not the same in each table row.

Thanks in advance
 
Not a clue on how to do that, as I do not know Word VBA.
But I know an LLM that might :), this was from ChatGPT

Code:
Sub GetNumberOfColumnsInCurrentRow()
    Dim tbl As Table
    Dim currentRow As Row
    Dim numCols As Integer

    ' Check if the selection is in a table
    If Selection.Information(wdWithInTable) Then
        Set tbl = Selection.Tables(1)
        Set currentRow = Selection.Rows(1)
        numCols = currentRow.Cells.Count
        MsgBox "Number of columns in the current row: " & numCols
    Else
        MsgBox "The selection is not inside a table."
    End If
End Sub
 
Yep... Word allows you to merge "neighbor" cells and it affects how they are addressed. But you should also try that with Excel. It allows merging of cells, too.
 

Users who are viewing this thread

Back
Top Bottom