0

I have a macro to create a custom list. The list is of the Spanish ordinals in feminine. This is the code:

Sub ListaFemenino ()
Dim arrNumbers As Variant
Dim i As Long
Dim rng As Range
arrNumbers = Split ("Primera Segunda Tercera Cuarta Quinta Sexta Séptima Octava Novena")
Set rng = Selection.Range
For i = 1 To rng.Paragraphs.Count
     With rng.Paragraphs (i) .Range
         .Text = arrNumbers (i - 1) & vbTab & .FormattedText
         .ParagraphFormat.TabHangingIndent 2
     End With
Next i
Exit Sub
End Sub

I need, if possible, that you give me the option, every time I want to apply it in the same document to continue the list or to restart it from 1, Primera in this case.

Actually what I need is for it to offer me the option to continue the numbering because restarting it from 1 is what it does.

1 Answer 1

2

Ref: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters

' 1 as default value if nothing is given as parameter
Sub ListaFemenino (s as long = 1) 

...
For i = s To rng.Paragraphs.Count
...

... with this you then need to detect from where to continue, how that is to be done is dependent on where you use it.

4
  • Thanks a lot, David: Could I use a certain style, which could also be called ListaFemenino, so that it detects where to proceed? So that every time I apply that style (ListaFemenino) and press the macro button, it is applied to the selected paragraphs, continuing the numbering from where it left off the previous time. What would the code look like in this case? Nov 5, 2021 at 18:32
  • Can someone help me with the code to only number the paragraphs with a certain style (FemaleList) even if they are not consecutive Nov 9, 2021 at 16:24
  • Dim arrNumbers As Variant Dim i As Long, j As Long Dim rng As Range arrNumbers = Split("Primera Segunda Tercera Cuarta Quinta Sexta Séptima Octava Novena") Set rng = Selection.Range j = 1 For i = 1 To rng.Paragraphs.Count If rng.Paragraphs(i).Style = "ListaFemenino" Then With rng.Paragraphs(i).Range .Text = arrNumbers(j - 1) & vbTab & .FormattedText .ParagraphFormat.TabHangingIndent 2 j = j + 1 End With End If Next i Nov 10, 2021 at 15:07
  • Hello again: I am trying with this new code but it does not work either. Nov 10, 2021 at 15:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .