
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
r = 2
inizio = 1
Call serie(inizio, r)
r = r + 1
While Cells(r, "A") <> ""
If Cells(r, "B") <> Cells(r - 1, "B") And Cells(r, "A") = Cells(r - 1, "A") Then
inizio = Cells(r - 1, "C") + 1
Call serie(inizio, r)
Else
If Left(Cells(r - 1, "D"), 1) <> "1" Then
inizio = Val(Left(Cells(r - 1, "D"), 1))
Else
inizio = 1
End If
Call serie(inizio, r)
End If
r = r + 1
Wend
End Sub
Sub serie(inizio, riga)
s = ""
For i = inizio To Cells(riga, "C")
s = s & i & ","
Next
s = Left(s, Len(s) - 1)
Cells(riga, "D") = s
End Sub |
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
r = 2
inizio = 1
Call serie(inizio, r)
r = r + 1
While Cells(r, "A") <> ""
b1 = Cells(r, "B").Value
b2 = Cells(r - 1, "B").Value
A1 = Cells(r, "A").Value
A2 = Cells(r - 1, "A").Value
If Cells(r, "B") <> Cells(r - 1, "B") And Cells(r, "A") = Cells(r - 1, "A") Then
inizio = Cells(r - 1, "C") + 1
Call serie(inizio, r)
Else
p = InStr(Cells(r - 1, "D"), ",")
If p = 0 Then p = 3 '<<<<<<<<<<<<<<
inizio1 = Left(Cells(r - 1, "D"), p - 1)
If inizio1 <> "1" Then
inizio = Val(inizio)
If inizio >= Cells(r, "C") Then inizio = 1
End If
Call serie(inizio, r)
End If
r = r + 1
Wend
End Sub
Sub serie(inizio, riga)
s = ""
For i = inizio To Cells(riga, "C")
s = s & i & ","
Next
s = Left(s, Len(s) - 1)
Cells(riga, "D") = s
End Sub |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Sub Scomponi()
'by scossa
Dim sScomp As String
Dim j As Long
Dim nStart As Long
Dim ws As Worksheet
Dim cella As Range
Dim nLR As Long
Set ws = ActiveSheet
nStart = 1
nLR = ws.Cells(Rows.Count, 3).End(xlUp).Row
For Each cella In ws.Range("C2:C" & nLR).Cells
sScomp = ""
If cella.Offset(0, -2) = cella.Offset(-1, -2) And _
cella.Offset(0, -1) <> cella.Offset(-1, -1) Then
nStart = cella.Offset(-1, 0) + 1
End If
If nStart >= cella.Value Then nStart = 1
For j = nStart To cella.Value
sScomp = sScomp & "," & j
Next
cella.Offset(0, 2) = Replace(sScomp, ",", "", 1, 1)
Next
Set ws = Nothing
End Sub |
