Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2016, 04:14 AM
highrise955 highrise955 is offline Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Windows 10 Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Office 2013
Advanced Beginner
Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6)
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6)

Hi All,

Another sequential numbering question.

I did a search for sequential numbering in this forum but none of the threads seemed to focus on what I needed. If I am mistaken, please direct me to the appropriate thread.

I have a table and the first cell in each row starts with a number. Most of the time simple sequential numbering works just fine. However, there are times that instead of using the next number in the sequence the users need to use #a, #b, #c..

For example...

1
2
3a
3b


3c
4
5
6

Below is the code I am using (borrowed ) to create each new row.
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)

Dim i As Long, j As Long, Prot As Variant
Dim tRows As Integer
Const Pwd As String = "" 'Insert password (if any) here

With CCtrl
  'Check that the Content Control is within our table.
  If .Range.InRange(ActiveDocument.Tables(1).Range) = False Then Exit Sub
  'Get the number of ContentControls in the table
  i = .Range.Tables(1).Range.ContentControls.Count - 1
  'Get our ContentControl's index # in the table
  j = ActiveDocument.Range(.Range.Tables(1).Range.Start, .Range.End).ContentControls.Count
  'Check that we're using the last content control
  If i <> j Then Exit Sub
End With


'Solicit user input
If MsgBox("Add a new dimension?", vbQuestion + vbYesNo, "Inspection Report") <> vbYes Then Exit Sub

With ActiveDocument
  ' Un-protect the document, if applicable
  Prot = .ProtectionType
  If .ProtectionType <> wdNoProtection Then
    Prot = .ProtectionType
    .Unprotect Password:=Pwd
  End If
  With Selection.Tables(1).Rows
    'Insert an empty paragraph after our table, then replace it with a replica of the last row
    With .Last.Range
      .Next.InsertBefore vbCr
      .Next.FormattedText = .FormattedText
    End With
    'Reset all content controls in the new last row
    For Each CCtrl In .Last.Range.ContentControls
      With CCtrl
        If .Type = wdContentControlCheckBox Then .Checked = False
        If .Type = wdContentControlRichText Or .Type = wdContentControlText Then .Range.Text = " "
        If .Type = wdContentControlDropdownList Then .DropdownListEntries(1).Select
        If .Type = wdContentControlComboBox Then .DropdownListEntries(1).Select
        If .Type = wdContentControlDate Then .Range.Text = " "
      End With
    Next
  End With
  
Below is the current method I am using to add the next number in sequence. 
FYI: "8" is the amount of rows in the header which needs to be ignored in
determining the amount of data input rows.
(I have no doubt the VBA experts will cringe at the inefficiency of this code.)
   Selection.EndKey Unit:=wdColumn
    Selection.StartOf Unit:=wdRow
    tRows = Selection.Information(wdMaximumNumberOfRows)
    tRows = tRows - 8
    Selection.Delete
    Selection.TypeText tRows
    
  ' Re-protect the document, if applicable
  .Protect Type:=Prot, Password:=Pwd
End With
End Sub
Obviously, I could just let the users type the numbers manually but I am trying to make this form as automated as possible. I'm not sure if I need to use a content control in the cell in question or if there is a way to do this without one.

Any input on how to proceed would be greatly appreciated.
Reply With Quote
  #2  
Old 03-20-2016, 08:47 AM
gmaxey gmaxey is offline Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Windows 7 32bit Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

As far as simply sequencing, I would insert a Seq Field where you want the numbering to appear and then update the field in the table.

However, for your basic question how is your macro supposed to know when the next number should be 3 or 3a? Or how long that sub-sequence should run before 3d becomes 4?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-20-2016, 04:47 PM
macropod's Avatar
macropod macropod is offline Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Windows 7 64bit Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If one used a Style-linked multi-level list numbering format, the numbering for both levels could largely take care of itself that way, too. The problem remains though, as to how the code would 'know' when to change Styles.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 03-20-2016, 11:31 PM
highrise955 highrise955 is offline Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Windows 10 Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Office 2013
Advanced Beginner
Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6)
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
If one used a Style-linked multi-level list numbering format, the numbering for both levels could largely take care of itself that way, too. The problem remains though, as to how the code would 'know' when to change Styles.
Quote:
Originally Posted by gmaxey View Post
As far as simply sequencing, I would insert a Seq Field where you want the numbering to appear and then update the field in the table.

However, for your basic question how is your macro supposed to know when the next number should be 3 or 3a? Or how long that sub-sequence should run before 3d becomes 4?
I was thinking that each time the user is asked if they want to add a new dimension...

Code:
If MsgBox("Add a new dimension?", vbQuestion + vbYesNo, "Inspection Report") <> vbYes Then Exit Sub
...the MsgBox can be replaced with a pop-up that gives them the option to continue with "single dimensions" or start a "multi-dimension". So if they select "single dimension" the code would add the next number in the sequence but if they selected "multi-dimension" the next number will have an "a" attached to it.

Then subsequent requests they would be asked to continue "multi" or move to next "single".

As I see it, the code would have to:

  1. Check the current rows number.
  2. Ascertain if a letter precedes the number.
    1. If Yes AND the user selected "Multi", keep the same number and add the next letter in the alphabet.
    2. If No AND the user selected "Multi", add the next number and add the letter "a" to it.
    3. If Yes AND the user selected "Single", add the next number only.
    4. If No AND the user selected "Single", add the next number only.
This would seem straight forward enough, but being a newbie it's a tad bit aggressive for me quite yet. If either of you can continue pointing me in the right direction, it would be most appreciated.
Reply With Quote
  #5  
Old 03-21-2016, 04:24 AM
macropod's Avatar
macropod macropod is offline Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Windows 7 64bit Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Surely it would be better to give the user just one question with a question and code like:
Code:
With Selection.Tables(1)
  With .Cell(.Rows.Count, 1).Range
    If MsgBox("Start/Continue Level 2 numbering?", vbYesNo, "Inspection Report") = vbYes Then
      .Style = "Heading 2"
    Else
      .Style = "Heading 1"
    End If
  End With
End With
Note: The above code only uses the 'Heading 1' & 'Heading 2' Styles for demonstration purposes.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) How do I do a Sequential Numbering? gburya Word VBA 26 07-04-2017 03:29 PM
Sequential numbering within Word Earthly Way Word VBA 1 12-02-2015 07:36 PM
Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Sequential page numbering im_rusahbh Word VBA 1 12-23-2013 05:28 PM
sequential numbering with macro grstools Word 5 08-15-2013 03:40 PM
Another Sequential Numbering Question (1,2,3a,3b,3c,4,5,6) Sequential Numbering jdwoods Word VBA 7 12-16-2011 05:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:30 AM.


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