macros for tables (2007)

A

aedcone

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
 
S

StevenM

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
 
J

Jules

Nice macro Steven.

If you select your second column and hit the layout tab and select split
cells it does what you require with Developer Tab on or off.
 
A

aedcone

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.
 
S

StevenM

To: Aedcone,

Well, you message appeared to ask for a macro, so I assumed that you had
some familiarity with them.

To Install a Macro:
Go to VBA editor via Tools > Macro > Visual Basic Editor (or Alt-F11).
Open the Project Explorer (if not open) , the shortcut key is Ctrl-R.
It will have the name “Project.â€
Click on the template where you would like to store your macro.
For example click on “Normal.â€
Insert a new Module with: Insert > Module.
It should have the name Module1.
(You can re-name your new module now or later by clicking on F4, this should
bring up the Properties Window. In the field following “(name)†you can
change the module’s name. Close the Properties window, now the new Module
should have a new name.)
The code window should now be open.
The code window has General & Declarations at the top.
If it is not open, double click on the Module.
Cut and past your macro into the code window.
You can store more than one macro in a module.
To run your macro, go back to your document and click on Alt-F8.
Alt-F8 will bring up the macro menu from which you can pick your macro and
run it.

Steven Craig Miller
 
S

StevenM

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
 
B

Bob Buckland ?:-\)

Hi Aedcone,

To add a bit to Steve's reply, regarding the location of the macro tools in Word 2007 :)

If you recorded macros in Word 2000, that ability is still available in Word 2007. You can right click the status bar at the bottom
of the Word 2007 screen and display the 'Macro Recording' option to be available to you there when you need it.

The Macro dialog that in Word 2000 was at
Tools=>Macro=>Macros
is, in Word 2007, located at
View=>Macros=>View Macros
and a 'Record Macro' button is also there.

In Word 2007 you can also turn on
'[x] Show Developer Tab in the Ribbon'
from
Office Button=>Word Options=>Popular (Alt, T, O)
and that tab includes buttons for the Visual Basic editor and the macro dialog.

===========
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. [snip]>>
--

Bob Buckland ?:)
MS Office System Products MVP

*Courtesy is not expensive and can pay big dividends*
 

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