Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Vladimiro,
ho la seguente situazione:
Vorrei che la colonna A non facesse parte del codice nella macro Aggiorna in modo da scriverci qualsiasi cosa.
Option Explicit
Option Compare Text
Public Sub Aggiorna()
Dim SH As Worksheet
Dim srcRng As Range, destRng As Range, rCell As Range
Dim i As Long, LRow As Long
Dim blFlag As Boolean
Set SH = ActiveSheet
With SH
LRow = LastRow(SH, .Columns("A:A"))
Set srcRng = .Range("A1:D1").Offset(LRow - 1)
With srcRng
If .Cells(1, 5).Value = "VINTA" Or .Cells(1, 5).Value = "PERSA" Then
blFlag = True
End If
End With
If blFlag = False Then
Exit Sub
End If
Set destRng = .Range("A" & LRow + 1)
End With
srcRng.Copy Destination:=destRng
With destRng.Cells(1, 3)
.Value = .Value - 1
End With
If UCase(srcRng.Cells(1, 5).Value) = "VINTA" Then
With destRng.Cells(1, 4)
.Value = .Value - 1
End With
End If
End Sub
Mi verrebbe da pensare di modificare questa riga di codice da così:
Set srcRng = .Range("A1:D1").Offset(LRow - 1)
a così:
Set srcRng = .Range("B1:D1").Offset(LRow - 1)
Però non implementa più nessuna cella.
Prova la seguente versione in cui le modifiche sono evidenziate in grassetto:
'=========>>
Option Explicit
'--------->>
Public Sub Aggiorna()
Dim SH As Worksheet
Dim srcRng As Range, destRng As Range, rCell As Range
Dim LRow As Long
Dim blFlag As Boolean
On Error GoTo XIT
Application.EnableEvents = False
Set SH = ActiveSheet
With SH
LRow = LastRow(SH, .Columns("B:B"))
Set srcRng = .Range("B1:E1").Offset(LRow - 1)
With srcRng
If .Cells(1, 4).Value = "VINTA" _
Or .Cells(1, 4).Value = "PERSA" Then
blFlag = True
End If
End With
If blFlag = False Then
Exit Sub
End If
Set destRng = .Range("B" & LRow + 1)
End With
srcRng.Copy Destination:=destRng
With destRng.Cells(1, 3)
.Value = .Value - 1
End With
If UCase(srcRng.Cells(1, 4).Value) = "VINTA" Then
With destRng.Cells(1, 2)
.Value = .Value - 1
End With
End If
XIT:
Application.EnableEvents = True
End Sub
'<<=========
===
Regards,
Norman