Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2015, 01:04 AM
srinidhi.mv88 srinidhi.mv88 is offline Dynamic table numbers Windows 7 64bit Dynamic table numbers Office 2010 64bit
Novice
Dynamic table numbers
 
Join Date: Apr 2015
Posts: 11
srinidhi.mv88 is on a distinguished road
Post Dynamic table numbers

Hello VBA Specialists,



I want a help to write a macro which find all the tables in document and adds numbers in incremental order.

The example table is Table.JPG

There are many tables in the document and all tables don't have same number of steps. Could anyone please help me to write the macro.

Thanks a lot.

With regards,
Srinidhi
Reply With Quote
  #2  
Old 06-17-2015, 03:57 AM
gmayor's Avatar
gmayor gmayor is offline Dynamic table numbers Windows 7 64bit Dynamic table numbers Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 3,861
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

Provided the tables are in the body of the document and not in headers footers, text boxes etc, and are similar to that shown, then the following should work.

Code:
Sub NumberTables()
Dim oTable As Table
Dim i As Long, j As Long
Dim oCell As Range
    i = 1
    For Each oTable In ActiveDocument.Tables
        For j = 2 To oTable.Rows.Count
            Set oCell = oTable.Cell(j, 1).Range
            oCell.End = oCell.End - 1
            oCell.Text = i & Chr(46) 'This is what goes in the cells!
            i = i + 1
        Next j
    Next oTable
lbl_Exit:
    Set oTable = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-17-2015, 04:52 AM
srinidhi.mv88 srinidhi.mv88 is offline Dynamic table numbers Windows 7 64bit Dynamic table numbers Office 2010 64bit
Novice
Dynamic table numbers
 
Join Date: Apr 2015
Posts: 11
srinidhi.mv88 is on a distinguished road
Default

It works partly, but the table numbers are incrementing and for each table I might need the numbering to start from the beginning. I will try to find out what could be done. If i am not, then please help me.

Thanks a lot

With regards,
Srinidhi
Reply With Quote
  #4  
Old 06-17-2015, 06:42 AM
gmayor's Avatar
gmayor gmayor is offline Dynamic table numbers Windows 7 64bit Dynamic table numbers Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 3,861
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

If you want the numbers to restart for each table, move the line
Code:
i = 1
to immediately AFTER the line
Code:
For Each oTable In ActiveDocument.Tables
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 06-17-2015, 06:49 AM
srinidhi.mv88 srinidhi.mv88 is offline Dynamic table numbers Windows 7 64bit Dynamic table numbers Office 2010 64bit
Novice
Dynamic table numbers
 
Join Date: Apr 2015
Posts: 11
srinidhi.mv88 is on a distinguished road
Smile

Solved. Thanks a lot
Reply With Quote
  #6  
Old 06-22-2015, 06:35 AM
srinidhi.mv88 srinidhi.mv88 is offline Dynamic table numbers Windows 7 64bit Dynamic table numbers Office 2010 64bit
Novice
Dynamic table numbers
 
Join Date: Apr 2015
Posts: 11
srinidhi.mv88 is on a distinguished road
Smile

Hi,

To the same issue, how could the not set all tables in ActiveDocument.Tables
but tables from page 2 to end. Because this macro is changing my title page, as there is a table which is generated automatically from the template file.

Thanks a lot.

With regards,
Srinidhi
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Mail Merged Table hanskimber Mail Merge 2 04-24-2015 11:21 PM
Dynamic table numbers Add content to Dynamic/Automatic Table of Contents rosenina18 Word 3 04-14-2015 05:15 AM
Dynamic Pivot Table in 2013 Alaska1 Excel 0 01-29-2015 10:33 AM
Dynamic table numbers Mail Merge Into Dynamic Table Jag618 Mail Merge 1 03-04-2013 11:26 PM
Dynamic table numbers VBA: Include Dynamic Sheet Name In Pivot Table Source Data ibrahimaa Excel Programming 2 04-28-2012 12:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:40 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2022 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft