Bom Dia,
Estou fazendo uma planilha de controle alterações,sou iniciante no uso de vba não estou conseguindo fazer que células F e G da aba log sejam preenchida automaticamente com as informações da plan1.
Na log deveria ser F = plan1 A1 e G ser = a célula da esquerda da informação inserida na H
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim iCell As Range
Dim iCol As Long
Dim iCounter As Long
Dim iLogRow As Long
Dim iRow As Long
Dim NowValue As Date
Dim OldTarget As Variant
With Application
.EnableEvents = False
.ScreenUpdating = False
On Error Resume Next
.Undo
If Target.Cells.Count > 1 Then
OldTarget = Target
Else
ReDim OldTarget(1 To 1, 1 To 1)
OldTarget(1, 1) = Target
End If
.Undo
On Error GoTo 0
End With
With Worksheets("Log")
NowValue = Now
For iRow = 1 To Target.Rows.Count
For iCol = 1 To Target.Columns.Count
iLogRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
Set iCell = Target(iRow, iCol)
.Cells(iLogRow, "A") = Sh.Name
.Cells(iLogRow, "B") = iCell.Address(0, 0)
.Cells(iLogRow, "C") = OldTarget(iRow, iCol)
.Cells(iLogRow, "I") = iCell
.Cells(iLogRow, "D") = NowValue
.Cells(iLogRow, "E") = VBA.Environ("username")
.Cells(iLogRow, "F") = iCell.Name
If iLogRow Mod 100 = 0 Then DoEvents
Next iCol
Next iRow
End With
If ActiveCell <> "" Then
ActiveCell.Offset(1, 0).Select
End If
ExitSub:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Obrigado a todos.
Postado : 23/09/2017 7:22 am