View Single Post
  #6   Report Post  
Posted to microsoft.public.word.tables
StevenM[_2_] StevenM[_2_] is offline
external usenet poster
 
Posts: 169
Default macros for tables (2007)

Aedcone,

I realize that I'm too late and that you have already taken care of the
situation, but for future reference. I believe the following macro is what
you asked for.

'
' TableSplitRows creates a table with two columns
' Where the second column has two rows for
' every row in the first column
'
Sub TableSplitRows()
Dim newDoc As Document
Dim oRange As Range
Dim oTable As Table
Dim nIndex As Long
Dim nRows As Long
'
' Change the value of nRows to how many rows
' is needed in the first column
'
nRows = 20
'
'
Set newDoc = Documents.Add
Set oRange = newDoc.Range
Set oTable = newDoc.Tables.Add(oRange, NumRows:=nRows, NumColumns:=2)
For nIndex = nRows To 1 Step -1
oTable.Columns(2).Cells(nIndex).Split NumRows:=2
Next nIndex
End Sub

Steven Craig Miller

"aedcone" wrote:

Hi Steve,

Column 1 has text in it. (200 rows)
I added a second column (no text) (200 rows) which I need to split in two
"cells" or "rows"... the second colum w/the two rows is associated with the
first column

Sorry, but I don't understand what you wrote/ or how your wrote it. I am
new 2007 and macros in this version are way beyond what I did to create
macros in Word 2000.

Sub TableSplitRows()
Dim newDoc As Document
Dim oRange As Range
Dim oTable As Table

Set newDoc = Documents.Add
Set oRange = newDoc.Range
Set oTable = newDoc.Tables.Add(oRange, NumRows:=2, NumColumns:=2)
oTable.Columns(2).Cells(2).Split NumRows:=2
oTable.Columns(2).Cells(1).Split NumRows:=2
End Sub

Anyway, thanks for whatever the above is... I have no idea if this is what i
was looking for... What i actually did is to create a table w/400 rows and
then merged two cells in column to form one cell. It was tedious and time
consuming, but I did get the job done.

"StevenM" wrote:

To: Aedcone,

I'm not following you. I think if you clarified your problem, you might find
someone posting an answer faster.

For example, you stated that you had a table with over 200 rows with text in
it.
Then you added a second column. Is the second column empty or does it have
text in it too?

The you stated that you needed to split the cells in the second column and
create two rows. Yes?

Now, if I'm understanding you here, the first column has over 200 rows, so
does that mean you want the second column to have over 400 rows? So that for
each row in column one, there will be two rows in column two?

For example, do you need a table which looks something like:

Sub TableSplitRows()
Dim newDoc As Document
Dim oRange As Range
Dim oTable As Table

Set newDoc = Documents.Add
Set oRange = newDoc.Range
Set oTable = newDoc.Tables.Add(oRange, NumRows:=2, NumColumns:=2)
oTable.Columns(2).Cells(2).Split NumRows:=2
oTable.Columns(2).Cells(1).Split NumRows:=2
End Sub

Steven Craig Miller

"aedcone" wrote:

I have table that consists of over 200 rows with text already in it. I've
added a second column. I now need to split the cells in the second colum
into two rows... This is to create a pedigree chart of sorts... I want to
create a macro to do this, but I can't seem to start the macro for
anything... Normally, I would right click in the cell, select split table,
change the column to 1, the rows to 2. This is macro I need to create, but
it won't let met right click in the cell whilst I have the "developer" tab
up, and when i go to the Insert table and select table, I don't get the menu
to split the table...

Help is needed asap... as it is, it's a big PIA to do this cell by cell...
and I thought a macro would help...

TIA