macro assegnazione stanze

Anonimo
2023-04-18T11:20:19+00:00

buongiorno, avrei bisogno di un aiuto con una macro.

ho in colonna c un numero (1 per le femmine, 2 per i maschi e 3 per le famiglie.)

in colonne D e E le date di arrivi e partenze.

in colonne G,H,I,J,K,L,M,N le stanze (mettiamo che sono da 5 posti (divise maschi o femmine o famiglie (colonne g,h,i femmine. colonne j,k,l maschi. colonne m,n famiglie)

vorrei che quando ci sono 5 numeri 1 (5 femmine x esempio) si riempisse la colonna g delle femmine, intanto che si riempie anche quale dei maschi e delle famiglie.

e che quando la prima colonna delle stanze delle femmine (G) é piena automaticamente mi riempie quella dopo (H) (e uguale per maschi e famiglie) e che se a una data di partenza di una femmina la prima colonna della stanza si svuota di 1 (quindi da 5 full diventa da 4) viene considerata come prima stanza utile per la prossima che arriva...

non so se é possibile..

ma sicuro si!

grazie

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

5 risposte

Ordina per: Più utili
  1. Anonimo
    2023-04-18T15:53:58+00:00

    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.

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2023-04-18T15:22:09+00:00

    anche un altra cosa. nelle colonne D, E ho le date di arrivo alla struttura e la partenza, quindi nella colonna E ci sono le date in cui man mano lasciano libere le stanze tornando a casa.

    supponiamo che alla riga 3 c`é la prima persona che lascia la struttura, avrei bisogno che nella prima riga e prima colonna utile si togliesse il numero 1 per lasciare spazio a il prossimo che si scrive al fondo della lista

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2023-04-18T15:16:43+00:00

    se scrivo una colonna di 12 valori da 1, al primo esegui me li da giustissimi, 5 nella prima stanza, 5 nella seconda stanza e 2 nella terza stanza.

    se schiaccio di nuovo esegui me ne aggiunge 3 alla cima della colonna I della terza stanza delle femmine (valore 1)

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2023-04-18T15:14:36+00:00

    buongiorno, siamo sulla buona strada ma c`é ancora del lavoro..

    quando ho tanti 1 nella colonna B, ( ne ho 12), nelle stanze assegnate me ne ritrovo 15, ce ne sono sempre alcuni in piu..

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Anonimo
    2023-04-18T12:08:08+00:00

    Ciao Marco

    Sono AnnaThomas e sarei felice di aiutarti con la tua domanda. In questo forum, siamo consumatori Microsoft proprio come te.

    Puoi usare questo:

    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 Next i End Sub

    I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

    Best Regards,

    AnnaThomas

    Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.

    Questa risposta è stata tradotta automaticamente. Di conseguenza, potrebbero esserci errori grammaticali o espressioni strane.

    La risposta è stata utile?

    0 commenti Nessun commento