On Wednesday 11/05/2022 casanmaner wrote:
> Hai provato a disabilitare il calcolo automatico, l'aggiornamento dello
> schermo e gli eventi prima di eseguire la procedura (per poi riabilitare alla
> fine)?
no, mi è venuto in mente ma non lo ho fatto, anche perché, prima di
aggiungere le righe per l'aggiornamento del valore, la routine si
limitava a colorare lo sfondo delle celle sbagliate, e anche con tutto
quanto attivo (aggiornamenti, calcolo, etc) impiegava appunto solo un
paio di secondi scarsi
farò comunque la prova
questo è il codice
Public Sub CheckSerialNo()
Dim Row, NumRows As Integer
Dim Serial, SerialID, Manufacturer As String
Dim Valid, Change As Boolean
Dim SerialNumberCol As Integer
SerialNumberCol = 11 ' column
Dim ManufacturerCol As Integer
ManufacturerCol = 7
Dim BackColor, NoBackColor As Integer
BackColor = 8 ' azzurrino ' era 6 ' yellow
NoBackColor = 2 ' bianco
ActiveSheet.Select
' start row
Row = 3
' loop
While Cells(Row, 1).Value <> ""
' read Serial & Manufacturer
Serial = UCase(Cells(Row, SerialNumberCol).Value)
Manufacturer = Cells(Row, ManufacturerCol).Value
Valid = False
Change = False
' format cells without backcolor
Cells(Row, ManufacturerCol).Interior.ColorIndex = NoBackColor
Cells(Row, SerialNumberCol).Interior.ColorIndex = NoBackColor
' test GINO
SerialID = Left(Serial, 5)
If SerialID = "MAR-N" And Manufacturer = "GINO" Then Valid = True:
GoTo ExitTest
If SerialID = "MAR-N" Then Manufacturer = "GINO": Change = True:
GoTo ExitTest
' test CARLO
SerialID = Left(Serial, 5)
If SerialID = "MAT-N" And Left(Manufacturer, 5) = "CARLO" Then
Valid = True: GoTo ExitTest
If SerialID = "MAT-N" Then Manufacturer = "CARLO": Change = True:
GoTo ExitTest
' altri test che non riporto
ExitTest:
If Valid = True Then GoTo NextRow
If Change = True Then Cells(Row, ManufacturerCol).Value =
Manufacturer: GoTo NextRow
' format cells with backcolor
Cells(Row, ManufacturerCol).Interior.ColorIndex = BackColor
Cells(Row, SerialNumberCol).Interior.ColorIndex = BackColor
NextRow:
' increase row
Row = Row + 1
' end loop
Wend
End Sub