Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
In base alla tua descrizione, sembra che tu voglia modificare il codice per tenere conto delle date di arrivo e partenza nelle colonne D ed E quando assegni le camere. Vuoi anche assicurarti che quando una persona lascia la struttura, la sua stanza sia liberata per la prossima persona sulla lista.
Ecco una versione modificata del codice che tiene conto delle date nelle colonne D ed E quando si assegnano le camere:
Sub AssignRooms() Dim lastRow As Long lastRow = Cells(Rows.Count, "C"). Fine(xlUp). Fila Dim i As Long Per i = 2 All'ultima riga Se le celle(i, "C"). Valore = 1 Allora If WorksheetFunction.CountIf(Range("G:G"), 1) < 5 Then Cells(i, "G"). Value = 1 ElseIf WorksheetFunction.CountIf(Range("H:H"), 1) < 5 Then Cells(i, "H"). Value = 1 ElseIf WorksheetFunction.CountIf(Range("I:I"), 1) < 5 Then Cells(i, "I"). Value = 1 End If ElseIf Cells(i, "C"). Value = 2 Then If WorksheetFunction.CountIf(Range("J:J"), 1) < 5 Then Cells(i, "J"). Value = 1 ElseIf WorksheetFunction.CountIf(Range("K:K"), 1) < 5 Then Cells(i, "K"). Value = 1 ElseIf WorksheetFunction.CountIf(Range("L:L"), 1) < 5 Then Cells(i, "L"). Value = 1 End If ElseIf Cells(i, "C"). Value = 3 Then If WorksheetFunction.CountIf(Range("M:M"), 1) < 5 Then Cells(i, "M"). Value = 1 ElseIf WorksheetFunction.CountIf(Range("N:N"), 1) < 5 Then Cells(i, "N"). Value = 1 End If End If
' Check if the person is leaving the structure and free up their room if necessary. If Cells(i, "E"). Value <= Date Then ' Person is leaving the structure. ' Find which room they are in and remove them from it. Dim col As Long For col = Range("G:M"). Column To Range("N:N"). Column ' Check columns G to N for room assignment. If Cells(i, col). Value = 1 Then ' Person is in this room. Cells(i, col). Value = "" ' Remove them from the room. Exit For ' No need to check other rooms. End If Next col End If
Next i
End Sub
Questa risposta è stata tradotta automaticamente. Di conseguenza, potrebbero esserci errori grammaticali o espressioni strane.