dcsimg
Results 1 to 2 of 2

Thread: Excel VBA Macro for automated paragraph numbering

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2018
    Posts
    10

    Excel VBA Macro for automated paragraph numbering

    Can somebody help with macro for automated paragraph numbering in my document?

    In column "A" I need to have paragraph numbers. I have three different types of numbering. They are "1", "1.1" and "1.11.1". In column "B" I have text and in column "C" I will insert corresponding text for macro to get information what number should be inserted in column "A". These options will be "main" for "1", "sub" for "1.1" and "sub-sub" for "1.11.1".

    So here is an example of my document.

    Code:
    A           B                  C
    
    1           Car parts        main
                 Some text
                 Some text
    1.1        Wheels           sub
                 Some text
    1.2        Bumper          sub
                 Some text
    1.3        Windshield      sub
                 Some text
    1.4        Motor             sub
                 Some text
    1.4.1     Cylinders        sub-sub
                 Some text
                 Some text
                 Some text
                 Some text
    1.4.2     Throttle          sub-sub
                 Some text
                 Some text
    1.4.3     Spark plugs    sub-sub
                 Some text
                 Some text
    
    2           Car options     main
                 Some text
                 Some text
                 Some text
                 Some text
                 Some text
    2.1        Leather seats  sub
                 Some text
                 Some text
    2.2        Xenon-lights    sub
                 Some text
    2.3        Transmission    sub
                 Some text
                 Some text
                 Some text
    2.3.1      Robot             sub-sub
                 Some text
                 Some text
                 Some text
    2.3.2      Automatic       sub-sub
                 Some text
                 Some text
    
    3           Other              main
                 Some text
                 Some text
    3.1        Pas. car           sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2018
    Posts
    10

    Re: Excel VBA Macro for automated paragraph numbering

    I have got this one from another forum. If somebody needs the same, here is the code:

    Code:
    Sub Addlevels()
       Dim m As Long, s As Long, ss As Long
       Dim Cl As Range
       
       For Each Cl In Range("C2", Range("C" & Rows.Count).End(xlUp))
          Select Case LCase(Cl.Value)
             Case "main"
                m = m + 1: s = 0: ss = 0
                Cl.Offset(, -2).Value = m
             Case "sub"
                s = s + 1: ss = 0
                Cl.Offset(, -2) = m & "." & s
             Case "sub-sub"
                ss = ss + 1
                Cl.Offset(, -2) = m & "." & s & "." & ss
          End Select
       Next Cl
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width