Eu havia anexado o arquivo excel sem a macro no primeiro post.
Agora anexei a q estou trabalhando... tem um monte de coisa como comentário, pois estou testando. Estou testando a soma dos meses também DateAdd para atualizar a data das parcelas automático tb.
Espero que possa me ajudar.
Controle de Movimentação da Empresa - teste data.rar
adicionado 43 minutos depois
Consegui atualizar as parcelas em cada aba.
Só não consegui ainda inserir a parcela (a linha) de acordo com data... somente no fim da planilha.
Código atualizado abaixo:
Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long, k As Long, m As Long, x As Long, i As Long, LinSel As Long
Dim lin As Integer
Dim D1 As Date, D2 As Date, D3 As Date
x = 1
lin = 15
If Target.Count > 1 Then Exit Sub
If Target.Column = 13 And Target.Value <> "" Then
On Error GoTo kno
Application.EnableEvents = False
m = Target.Offset(, -1).Value - Target.Value: k = ActiveSheet.Index
D1 = CDate(Target.Offset(, -12).Value)
For i = k + 1 To k + m
With Sheets(i)
Do While Sheets(i).Cells(lin, 1).Value <> ""
D2 = CDate(Sheets(i).Cells(lin, 1))
D3 = DateAdd("m", i - 1, D1)
If CDate(D3) <= CDate(D2) Then
LinSel = Sheets(i).Cells(lin, 1).EntireRow.Insert 'CopyOrigin:=xlFormatFromLeftOrAbove
'Sheets(i).Range(Cells(Target.Row, 1), Cells(Target.Row, 13)).Copy Sheets(i).Cells(x, 1)
LR = .LinSel.Row
.Cells(LR, 1).Resize(, 13).Value = _
Cells(Target.Row, 1).Resize(, 13).Value
.Cells(LR, 1).Value = D3
.Cells(LR, 13).Value = .Cells(LR, 13).Value + x
x = x + 1
'Selection.PasteSpecial xlPasteValues
Else
lin = lin + 1
End If
Loop
D3 = DateAdd("m", i - 1, D1)
MsgBox (D3)
LR = .Cells(Rows.Count, 1).End(3)(2).Row
.Cells(LR, 1).Resize(, 13).Value = _
Cells(Target.Row, 1).Resize(, 13).Value
.Cells(LR, 1).Value = D3
.Cells(LR, 13).Value = .Cells(LR, 13).Value + x
x = x + 1
End With
Next i
kno:
Application.EnableEvents = True
End If
End Sub