#1
|
||||
|
||||
Identifying Table Cell Addresses
Word supports tables with up to 63 columns and an apparently unlimited rows (provided you keep within the 32Mb document text limit). Unlike Excel, however, Word doesn’t automatically indicate which cell your cursor is in. This can be difficult to work out in a large table, especially when you start working with merged cells. The following macro outputs the address of the table's selected cell range and the table’s last cell address on Word’s Status Bar: Code:
Sub CellRange() 'Sourced from: https://www.msofficeforums.com/word-tables/26997-identifying-table-cell-addresses.html Dim StrAddr As String ' This macro displays the address of a table's selected cell range ' and the table’s last cell address on Word's Status Bar With Selection If .Information(wdWithInTable) = True Then StrAddr = "The selected " If .Cells.Count = 1 Then StrAddr = StrAddr & "cell address is: " Else StrAddr = StrAddr & "cells span: " End If StrAddr = StrAddr & ColAddr(.Cells(1).ColumnIndex) & .Cells(1).RowIndex If .Cells.Count > 1 Then StrAddr = StrAddr & ":" & ColAddr(.Characters.Last.Cells(1).ColumnIndex) & _ .Characters.Last.Cells(1).RowIndex End If With .Tables(1).Range StrAddr = StrAddr & ". The table's last cell is at: " & _ ColAddr(.Cells(.Cells.Count).ColumnIndex) & .Cells(.Cells.Count).RowIndex End With StatusBar = StrAddr Else StatusBar = "The selection is not in a table!" End If End With End Sub Function ColAddr(i As Long) As String If i > 26 Then ColAddr = Chr(64 + Int(i / 26)) & Chr(64 + (i Mod 26)) Else ColAddr = Chr(64 + i) End If End Function Code:
StrAddr = StrAddr & ". The table's last cell is at: " & _ ColAddr(.Cells(.Cells.Count).ColumnIndex) & .Cells(.Cells.Count).RowIndex End With StatusBar = StrAddr Else StatusBar = "The selection is not in a table!" End If Code:
StrAddr = StrAddr & vbCr & "The table's last cell is at: " & _ ColAddr(.Cells(.Cells.Count).ColumnIndex) & .Cells(.Cells.Count).RowIndex End With MsgBox StrAddr, vbOKOnly Else MsgBox "The selection is not in a table.", vbExclamation End If For Mac macro installation & usage instructions, see: Word:mac - Install a Macro.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Move table cell contents from one table to another table or cell in same table | donaldadams1951 | Word VBA | 4 | 02-04-2015 03:54 PM |
Table with text that flows from cell to cell | hwrigley | Word Tables | 7 | 02-18-2014 02:59 AM |
Identifying Postcodes. | Chayes | Word VBA | 13 | 09-21-2013 06:29 AM |
Auto-populate an MS Word table cell with text from a diff cell? | dreamrthts | Word Tables | 0 | 03-20-2009 01:49 PM |
Identifying the Dynamic Connector | cyberbhai | Misc | 0 | 12-14-2005 03:55 AM |