Ciao ragazzi, saluto tutti dopo lungo tempo di assenza.
Stavolta ho pensato di dedicarmi a un planning.
Vi chiedo se qualcuno può aiutarmi perché non riesco a capire dove stia l'errore.
Su questo codice ho l'errore riportato e la dCell mi rende "Nothing"
Grazie in anticipo.
________________________________________________________________________
Sub Bookings()
'dichiaro le variabili
Dim bCell As Range, Rm As Range, Dt As Range, orange As Range
Dim dCell As Range, aCell As Range, Cl As Range, Nn As Range, ID As Range
Dim Fws As Worksheet, Bws As Worksheet
Dim x As Integer
Dim lastrow As Long
Dim oCell As Variant
Dim iCell As Variant
On Error Resume Next
'variabili
Set Fws = Sheet4 'foglio dati
Set Bws = Sheet2 'foglio booking
'filtra i dati
FilterRng
'imposta l'intervallo per il loop
lastrow = Fws.Range("AJ" & Rows.Count).End(xlUp).Row
Set orange = Fws.Range("AJ9:AJ" & lastrow)
'cancella valori dal calendario
Bws.Range("E13:BH40").ClearContents
Bws.Range("E13:BH40").Interior.ColorIndex = xlNone
'LOOP 1"""""""""""""""""""""""""""""""
'imposta la variabile per il numero di righe e loop
For x = 13 To 40
'imposta la variabile della stanza
Set Rm = Bws.Cells(x, 3)
Debug.Print Rm
'LOOP 2"""""""""""""""""""""""""""""'
'scorrere attraverso l'intervallo di colonne
For Each dCell In Bws.Range(Cells(x, 5), Cells(x, 60))
If Not dCell Is Nothing Then
'*****************************************
' Bws.Range <Metodo range dell'oggetto Worksheet non riusito.>
'********************************************
'imposta la variabile della data
Set Dt = Cells(12, dCell.Column)
'FUNCTION""""""""""""""""""""
'trova la stanza
Set aCell = orange.Find(What:=Rm, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
'imposta la variabile della stanza
Set bCell = aCell
'LOOP 3"""""""""""""""""""""""
'scorrere tra i dati filtrati
Do
'trova la stanza successiva con una prenotazione
Set aCell = orange.FindNext(After:=aCell)
'stabilire le date da aggiungere
If aCell.Offset(0, 1).Value <= Dt.Value And aCell.Offset(0, 3).Value >= Dt.Value Then
'assegna le variabili
Set Cl = aCell.Cells(1, 5) 'stato
Set Nn = aCell.Cells(1, 10) 'nome
Set ID = aCell.Offset(0, -1) 'ID
'aggiungi i nomi e riassegna
If oCell <> Nn Or iCell <> ID Then
dCell.Value = Nn
Set oCell = Nn
Set iCell = ID
End If
'aggiunge colori
Select Case Cl
Case "Prenotato"
dCell.Interior.ColorIndex = 27
Case "Confermato"
dCell.Interior.ColorIndex = 24
Case "Pagato"
dCell.Interior.ColorIndex = 4
Case "Cancellato"
dCell.Interior.ColorIndex = 38
End Select
End If
'esce quando vengono trovati valori
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
Else
Exit Do
End If
'"""""""""""
Loop 'LOOP 3 fine
'"""""""""""""""""""""""""""
End If
End If
'""""""""""'
Next dCell 'LOOP 2 fine
'"""""""""""""
Next x 'LOOP 1 fine
'"""""""""""""""
On Error GoTo 0
End Sub