counting cells in a row

T

Tony Logan

I want the user to be able to select a row (always a single row) in a table and have a macro perform "Action A" to the first cell (align contents left/bottom, for example), then "Action B" (align contents center/bottom, for example) to the remaining cells

I'm not sure how to write the code that would identify the first cell as cell 1, second cell as cell 2, etc

Thanks

-TL
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?VG9ueSBMb2dhbg==?=,
I want the user to be able to select a row (always a single row) in a table and have a macro perform "Action A" to the first cell (align contents left/bottom, for example), then "Action B" (align contents center/bottom, for example) to the remaining cells.

I'm not sure how to write the code that would identify the first cell as cell 1, second cell as cell 2, etc.
Something like this? (Note, the following allows for cells merged vertically)

Sub DoCellsInRow()
Dim iRowIndex As Long, iColIndex As Long
Dim tbl As Word.Table, iCellCounter As Long
'Handles merged cells
If Selection.Information(wdWithInTable) Then
Set tbl = Selection.Tables(1)
iRowIndex = Selection.Information(wdStartOfRangeRowNumber)
iColIndex = tbl.Columns.Count
For iCellCounter = 1 To iColIndex
If iCellCounter = 1 Then
tbl.Cell(iRowIndex, iCellCounter).Range.Text = _
"First"
Else
On Error Resume Next
tbl.Cell(iRowIndex, iCellCounter).Range.Text = _
"Col " & iCellCounter
On Error GoTo 0
End If
Next
End If
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :)
 
B

BONNIE

YOUR DON'T HAVE TO WRITE A CODE. OPEN THE TABLE. PLACE YOUR CURSOR IN THE FIRST CELL AND CREAT A MACRO THAT WILL DO EACH THING THAT OYU WANT DONE, GIV EHT MACRO A NAME THAT WILL HELP YOU REMEMBER WHAT IT DOES AND ONCE OYU'VE FINISHED, STOP RECORDING.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top