Moderatori: Anthony47, Flash30005
Function Numeraz(ByRef myRan As Range) As Variant
Dim Dizionario, wArr, tArr() As String, myMatch
Dim nArr() As Long
'
Dizionario = Array("Zc", "Titolo1", "Titolo2", "Titolo3", "Titolo4") '<<< Zc + L'elenco dei livelli
'
ReDim nArr(1 To UBound(Dizionario) + 3)
wArr = myRan.Value
ReDim tArr(1 To UBound(wArr), 1 To 1)
For i = 1 To UBound(wArr)
myMatch = Application.Match(wArr(i, 1), Dizionario, False)
If Not IsError(myMatch) Then
For j = myMatch To UBound(Dizionario)
nArr(j) = 0
Next j
nArr(myMatch - 1) = nArr(myMatch - 1) + 1
'End If
For j = 1 To UBound(Dizionario)
If nArr(j) > 0 Or nArr(j + 1) > 0 Or nArr(j + 2) > 0 Or nArr(j + 3) > 0 Then
tArr(i, 1) = tArr(i, 1) & "." & nArr(j)
End If
Next j
tArr(i, 1) = Mid(tArr(i, 1), 2)
End If
Next i
Numeraz = tArr
End Function
=Numeraz(B1:B20)
Sub Numera()
Dim ele
Dim i As Long, a As Long, b As Long, c As Long
a = 0: b = 0: c = 0
ele = Array("Zc", "Titolo1", "Titolo2", "Titolo3")
For i = 1 To Cells(Rows.Count, 2).End(xlUp).Row
If Cells(i, 2) = ele(1) Then
a = a + 1
b = 0: c = 0
Cells(i, 10) = a
ElseIf Cells(i, 2) = ele(2) Then
b = b + 1
Cells(i, 10) = a & "." & b
ElseIf Cells(i, 2) = ele(3) Then
c = c + 1
Cells(i, 10) = a & "." & b & "." & c
End If
Next i
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'
ckArea = "C1:C100" '<<< L'area dei titoli
'
If Not Application.Intersect(Target, Range(ckArea)) Is Nothing Then
Call Numera
End If
End Sub
Sub Numera()
Dim ele
Dim i As Long, a As Long, b As Long, c As Long
a = 0: b = 0: c = 0: d = 0
ele = Array("Zc", "Titolo1", "Titolo2", "Titolo3", "Titolo4")
For j = 2 To Cells(Rows.Count, 2).End(xlUp).Row 'controlla la sequenza dei titoli
If Cells(j, 2) = ele(3) And Cells(j - 1, 2) = ele(1) Then
MsgBox ("Titolo3 senza Titolo2")
Exit Sub
End If
Next j
For l = 2 To Cells(Rows.Count, 2).End(xlUp).Row
If Cells(l, 2) = ele(4) And Cells(l - 1, 2) = ele(1) Or Cells(l, 2) = ele(4) And Cells(l - 1, 2) = ele(2) Then
MsgBox ("Titolo4 senza Titolo3")
Exit Sub
End If
Next l
For i = 1 To Cells(Rows.Count, 2).End(xlUp).Row 'scrive i titoli
If Cells(i, 2) = ele(1) Then
a = a + 1
b = 0: c = 0: d = 0
Cells(i, 10) = a
ElseIf Cells(i, 2) = ele(2) Then
b = b + 1
c = 0: d = 0
Cells(i, 10) = a & "." & b
ElseIf Cells(i, 2) = ele(3) Then
c = c + 1
d = 0
Cells(i, 10) = a & "." & b & "." & c
ElseIf Cells(i, 2) = ele(4) Then
d = d + 1
Cells(i, 10) = a & "." & b & "." & c & "." & d
End If
Next i
End Sub
Torna a Applicazioni Office Windows
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 5 |
sal vare doc in word in PDF editabile Autore: danibi60 |
Forum: Applicazioni Office Windows Risposte: 2 |
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 7 |
Visitano il forum: Nessuno e 15 ospiti