Importare dati da una matrice su 2 listbox

Anonimo
2016-06-21T09:57:27+00:00

Buongiorno a tutti,

avrei bisogno di un aiuto nel creare una routine per caricare dei dati in due listbox in funzione di due condizioni.

Venendo al dunque, ho su una userform 3 listbox, nella prima un elenco di nomi e gradi che sono le colonne A e B del foglio di lavoro.

Nelle intestazioni delle altre colonne ci sono 30 corsi in 30 colonne. Nell'incrocio tra le colonne e le righe ho se quel determinato corso è obbligatorio oppura raccomandato per la persona selezionata.

Quindi al momento che clicco su una persona vorrei che una routine spazzoli tutti i corsi ed ad ogni intersezione con la riga mi inserisca quelli obbligatori in una listbox e quelli raccomandati nella seconda listbox. Ovviamente se l'intersezione risulta vuota non aggiunge nessun corso. Spero di essere stato chiaro nella spiegazione e vi allego una parte della tabella con i dati mensionati.

Anticipatamente ringrazio

Saluti

Giuseppe

JOB TITLE SURMANE & NAME PERSONAL SURVIVAL TECNIQUES STCW A-VI/1-1 FIRE PREVENTION AND FIREFIGHTING STCW  A-VI/1-2 ELEMENTARY FIRST AID STCW A-VI/1-3 PERSONAL SAFETY & SOCIAL RESPONSIBILIES STCW A-VI/1-4 PROFICENCY IN SURVIVAL CRAFTS AND RESCUE BOATS (other than fast rescue boat) STCW A-VI/2<br>(7*) ADVANCED FIRE FIGHTING STCW A-VI/3 (7*) FAST RESCUE BOATS STCW  A-VI/2 MEDICAL FIRST AID STCW A-VI/4-1 MEDICAL CARE STCW A-VI/4-2 GMDSS STCW A- IV/2
Master LANGELLA GIUSEPPE M M M M M M M M
Master CASTELLANO GIUSEPPE M M M M M M M M
Chief Mate PITINO SALVATORE M M M M M M R M M
Chief Mate SEKULJA RAJKO M M M M M M R M M
2nd Mate PERSIANO RAFFAELE M M M M M M R R R M
2nd Mate LANDINI ANDREA M M M M M M R R R M
3rd Mate BAZIN ALEKSANDR M M M M M M R R R M
3rd Mate FILIPCIUK ANDREJ M M M M M M R R M
Chief Engineer ANICHINI FEDERICO M M M M M M R
Chief Engineer RIVANO VICTOR M M M M M M R
1st Engineer SOLARI FABIO M M M M M M R R
1st Engineer MORGERA GIUSEPPE M M M M M M R R
2nd Engineer FAVATELLA ANTONIO M M M M M M R R
2nd Engineer LUCIA LUIGI M M M M M M R R
2nd Engineer SENYAK YURIY M M M M R R R R
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
Risposta accettata dall'autore della domanda
Anonimo
2016-06-23T00:28:30+00:00

Prova a vedere questo file di esempio (#5) dove alla UserForm ho aggiunto delle ListBox dedicate alle "intestazioni multiple" e dove ho modificato i comandi nell'evento Initialize della user.

Se poi tu volessi impostare anche la larghezza delle colonne potresti dichiarare delle costanti di testo con le misure desiderate e poi assegnare quelle misure alle rispettive TextBox (sia quelle dedicate a contenere i dati veri e propri che quelle dedicate a contenere le intestazioni multiple). In questo modo avresti i dati sempre allineati.

Questo il nuovo file: File esempio #5

Questo il codice, all'interno della User, che ho modificato per tener conto delle ListBox che fanno da intestazione.

'---

Private Sub UserForm_Initialize()

  Dim sLB_Header_MaritimeCrew As Variant

  Dim sLB_Header_CertificateOnBoard As Variant

  Dim sLB_Header_CertificateExpired As Variant

  sLB_Header_MaritimeCrew = Array("Grado", "Cognome e Nome", "Badge Nr")

  sLB_Header_CertificateOnBoard = Array("Certificato", "Data Scadenza")

  sLB_Header_CertificateExpired = Array("Certificato", "Data Scadenza", "Giorni scadenza")

  Set Wb = ThisWorkbook

  With Wb

    Set Ws1 = .Worksheets(sNameWs1)

    Set Ws1Rng1 = Ws1.Range(sWs1Rng1)

    Set CR1 = Ws1Rng1.CurrentRegion

    NumRowCR1 = CR1.Rows.Count

    NumColumnCR1 = CR1.Columns.Count

    Set Ws2 = .Worksheets(sNameWs2)

    Set Ws2Rng1 = Ws2.Range(sWs2Rng1)

    Set CR2 = Ws2Rng1.CurrentRegion

    NumRowCR2 = CR2.Rows.Count

    NumColumnCR2 = CR2.Columns.Count

  End With

  DataOdierna = Date

  With Me

    With .LB_MaritimeCrew

      .List() = CR1.Offset(1, 0).Resize(NumRowCR1 - 1, 3).Value

      .ColumnCount = 3

    End With

    With .LB_Header_MaritimeCrew

      .Column() = sLB_Header_MaritimeCrew

      .ColumnCount = 3

    End With

    With .LB_Header_CertificateOnBoard

      .Column() = sLB_Header_CertificateOnBoard

      .ColumnCount = 2

    End With

    With .LB_Header_CertificateExpired

      .Column() = sLB_Header_CertificateExpired

      .ColumnCount = 3

    End With

    .LB_CertificateOnBoard.ColumnCount = 2

    .LB_CertificateExpired.ColumnCount = 3

  End With

End Sub

'---

p.s. mi sono accorto che avevo nominato la listbox dei certificati scaduti LB_CertificateExipired (con una i dopo la x) e ho provveduto a modificare il nome della TextBox e i relativi riferimenti nel codice con LB_CertificateExpired

p.p.s questo l'aspetto grafico della UserForm con le listbox delle intestazioni colorate di "giallo chiaro"

![](http://fud.community.services.support.microsoft.com/Fud/FileDownloadHandler.ashx?fid=c6cd949e-07d5-4a2d-9cfc-4e1045bce1c3)

La risposta è stata utile?

0 commenti Nessun commento
Risposta accettata dall'autore della domanda
Anonimo
2016-06-22T21:16:50+00:00

Dopo la partita dell'Italia, un po' deludente a dire il vero, ti propongo questo file esempio (il quarto :-) ) dove ho inserito una UserForm2.

File esempio #4

Tutto il codice (così Mauro non mi cazzia :-D) è presente all'interno della UserForm2.

Alle ListBox ho dato dei nomi "particolari" (LB_MaritimeCrew, LB_Mandatory, LB_Racommended, LB_CertificateOnBoard, LB_CertificateExipired).

Questo il codice presente all'interno della UserForm2 (caricabile tramite il pulsante presente nel Foglio1).

'---

Option Explicit

Const sNameWs1 As String = "Foglio1"

Const sWs1Rng1 As String = "A1"

Const sNameWs2 As String = "Foglio2"

Const sWs2Rng1 As String = "A1"

Dim Wb As Workbook

Dim Ws1 As Worksheet

Dim Ws1Rng1 As Range

Dim CR1 As Range

Dim NumRowCR1 As Integer

Dim NumColumnCR1 As Integer

Dim Ws2 As Worksheet

Dim Ws2Rng1 As Range

Dim CR2 As Range

Dim NumRowCR2 As Integer

Dim NumColumnCR2 As Integer

Dim DataOdierna As Date

Private Sub UserForm_Initialize()

  Set Wb = ThisWorkbook

  With Wb

    Set Ws1 = .Worksheets(sNameWs1)

    Set Ws1Rng1 = Ws1.Range(sWs1Rng1)

    Set CR1 = Ws1Rng1.CurrentRegion

    NumRowCR1 = CR1.Rows.Count

    NumColumnCR1 = CR1.Columns.Count

    Set Ws2 = .Worksheets(sNameWs2)

    Set Ws2Rng1 = Ws2.Range(sWs2Rng1)

    Set CR2 = Ws2Rng1.CurrentRegion

    NumRowCR2 = CR2.Rows.Count

    NumColumnCR2 = CR2.Columns.Count

  End With

  DataOdierna = Date

  With Me

    With .LB_MaritimeCrew

      .List() = CR1.Offset(1, 0).Resize(NumRowCR1 - 1, 3).Value

      .ColumnCount = 3

    End With

    .LB_CertificateOnBoard.ColumnCount = 2

    .LB_CertificateExipired.ColumnCount = 3

  End With

End Sub

Private Sub LB_MaritimeCrew_Click()

  Dim sJobTitle As String

  Dim sNomePersonale As String

  Dim rngFindCorsiJobTitle As Range

  Dim rngFindCorsiPersonale As Range

  Dim i As Integer, t As Integer

  With Me

    .LB_Mandatory.Clear

    .LB_Racommended.Clear

    .LB_CertificateOnBoard.Clear

    .LB_CertificateExipired.Clear

  With .LB_MaritimeCrew

    sJobTitle = .List(.ListIndex, 0)

    sNomePersonale = .List(.ListIndex, 1)

  End With

  Set rngFindCorsiJobTitle = CR2.Resize(NumRowCR2, 1).Find(What:=sJobTitle, After:=Ws2Rng1, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows)

  Set rngFindCorsiPersonale = CR1.Resize(NumRowCR1, 2).Find(What:=sNomePersonale, After:=Ws1Rng1.Offset(0, 1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows)

    For i = 1 To NumColumnCR2 - 1

      If UCase(rngFindCorsiJobTitle.Offset(0, i).Value) = "M" Then

        .LB_Mandatory.AddItem Ws2Rng1.Offset(0, i).Value

      End If

      If UCase(rngFindCorsiJobTitle.Offset(0, i).Value) = "R" Then

        .LB_Racommended.AddItem Ws2Rng1.Offset(0, i).Value

      End If

        For t = 1 To NumColumnCR1 - 3

          If Ws1Rng1.Offset(0, t + 2).Value = Ws2Rng1.Offset(0, i).Value Then

            If rngFindCorsiPersonale.Offset(0, t + 1).Value <> "" Then

              If IsDate(rngFindCorsiPersonale.Offset(0, t + 1).Value) And _

                 UCase(rngFindCorsiJobTitle.Offset(0, i).Value) = "M" Then '<------------

                If rngFindCorsiPersonale.Offset(0, t + 1).Value > DataOdierna + 90 Then

                  With .LB_CertificateOnBoard

                    .AddItem

                    .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                    .List(.ListCount - 1, 1) = rngFindCorsiPersonale.Offset(0, t + 1).Value

                  End With

                Else

                  With .LB_CertificateExipired

                    .AddItem

                    .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                    .List(.ListCount - 1, 1) = rngFindCorsiPersonale.Offset(0, t + 1).Value

                    .List(.ListCount - 1, 2) = rngFindCorsiPersonale.Offset(0, t + 1).Value - DataOdierna

                  End With

                End If

              Else

                With .LB_CertificateOnBoard

                  .AddItem

                  .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                  .List(.ListCount - 1, 1) = rngFindCorsiPersonale.Offset(0, t + 1).Value

                End With

              End If

            Else

              If UCase(rngFindCorsiJobTitle.Offset(0, i).Value) = "M" Then

                With .LB_CertificateExipired

                  .AddItem

                  .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                  .List(.ListCount - 1, 1) = "To be done"

                  .List(.ListCount - 1, 2) = "!!!!!"

                End With

              End If

            End If

          End If

        Next t

    Next i

  End With

End Sub

'---

Prova a verificare se riesce a fare ciò che è nelle tue intenzioni.

La risposta è stata utile?

0 commenti Nessun commento

68 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2016-06-24T06:03:16+00:00

    Infine vorrei cambiare la colonna 3 della LB_Crew da "badge nr." a "Nationality" ed inserirla anche ai tecnici.

    Perdona Giuseppe ma queste decisioni vanno prese da subito. Non tanto per il cambio di intestazione nel foglio dove sono presenti i marittimi, per il quale semplicemente la colonna Badge Nr. diventerà Nationality e nei record al posto del numero di Badge inserirai la nazionalità, ma il fatto di avere un terzo campo, prima dei campi dedicati ai ruoli, nel foglio dei tecnici (avevo evidenziato questa cosa della mancanza di quella colonna).

    Avendolo saputo prima avrei scritto il codice in maneria differente o con un altro approcio, utilizzando una sola procedura di caricamento dati ma solo facendo in modo che in base alla TabStrip i riferimenti a Ws1 e Ws2 (e gli altri) cambiassero facendo riferimento ai relativi fogli o, anche utilizzando lo stesso approcio con due distinte procedure di caricamento, comunque i riferimenti degli offset non sarebbero cambiati tra la procedura che carica i dati dei marittimi rispetto a quelli dei tecnici.

    Comunque per aggiungere una terza colonna al foglio tecnici dovrai modificare la procedura LoadTechnicalCrew in modo che il ciclo con la variabile "t" tenga conto che ora c'è un'altra colonna da non considerare per la ricerca.

    In pratica il ciclo, che inizierà sempre da 1, dovrà fermarsi di un numero prima (quindi NumColumnCR3 - 2 diventerà NumColumnCR3 - 3) e dove sono presenti gli offset che fanno riferimento a "t" dovrai aggiungere un ulteriore 1 (quindi ad es. dove hai t dovrai inserire t+1 e dove hai t+1 dovrai sostituire t+2).

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2016-06-24T04:06:59+00:00

    Ciao Casanmaner,

    e che dire, funziona tutto egreggiamente :)

    Ho solo modificato come hai consigliato tu il seguente codice inserendo la msgbox in modo da togliere il focus e quindi ogni qual volta selezioni un cert. con la nota esce la msgbox. Tanto in quell'area non si lavora se non per vedere cosa dice la nota.

     With Me

        With .LB_Mandatory

          Select Case Right(.List(.ListIndex), 4)

            Case "(1*)"

             MsgBox ("test")

            Case "(2*)"

             MsgBox ("test")

            Case "(3*)"

             MsgBox ("test")

            Case "(4*)"

             MsgBox ("test")

            Case "(5*)"

             MsgBox ("test")

            Case Else

             .ControlTipText = Empty

          End Select

        End With

      End With

    Adesso che la lettura dei corsi e delle matrici sono complete, avrei bisogno di avere un altro codice per l'inserimento dell'equipaggio e modifica o inserimento dei corsi relativi alla singola persona. Io ho pensato di usare altre userform chiamate con due optionbutton come in figura sotto:

    Ed alle due otion, associare due userform ove poter apportare modifiche sia all'equipaggio (new entry o resigned) che ai certificati (delete and update or from "R" to "M").

    Infine vorrei cambiare la colonna 3 della LB_Crew da "badge nr." a "Nationality" ed inserirla anche ai tecnici.

    Guarda il codice che avevo fatto io sul vecchio programma :)

    che vergogna !!!! Ah ah ah 

    Private Sub crew_Click()

    Dim mio As String

    Dim tuo As String

    Dim nostro As String

    Dim accetto

    Dim cv

    Dim X

    Dim Y

    If UserForm1.TabStrip1.Value = 0 Then

    mio = UserForm1.crew.ListIndex + 2

    tuo = "A" + mio

    Range(tuo).Select

    UserForm1.TextBox45.Text = ActiveCell.Offset(0, 1)

    UserForm1.Label56.Caption = ActiveCell

    UserForm1.Label58.Caption = ActiveCell.Offset(0, 2)

    UserForm1.owncertificate.Clear

    UserForm1.underexpiration.Clear

    Sheets("calcolo").Activate

    Sheets("calcolo").Range("A1:AW1").Select

    If Cells.Find(What:=Sheets("expats").Range(tuo)) Is Nothing Then

    Sheets("Expats").Select

    accetto = MsgBox("OPS!!!! Found an error !!!", vbInformation, "Read Message!")

    UserForm5.ComboBox1.Value = ActiveCell

    UserForm5.TextBox1.Text = ActiveCell.Offset(0, 1)

    UserForm5.TextBox2.Text = ActiveCell.Offset(0, 2)

    UserForm5.Show

    Exit Sub

    Else

    Cells.Find(What:=Sheets("expats").Range(tuo), After:=ActiveCell, LookIn:=xlFormulas, LookAt _

            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

            False, SearchFormat:=False).Activate

        ActiveCell.Offset(1, 0).Activate

        UserForm1.mandatory.RowSource = ActiveCell.Address & ":" & ActiveCell.Offset(20, 0).Address

    Sheets("expats").Select

    End If

    ElseIf UserForm1.TabStrip1.Value = 1 Then

    certificates.Show

    End If

    Dim n

    Dim a

    Dim B

    Dim c

    Dim CL As Object

    cv = 0

    For X = 4 To 49

    Y = ActiveCell.Columns(X).Address

    For Each CL In Range(Y)

    If CL.Value = "" Then

    cv = cv + 1

    ElseIf CL.Value <> "" Then

    n = CL.Row - 1

    a = UserForm1.underexpiration.ListCount

    B = UserForm1.owncertificate.ListCount

    UserForm1.owncertificate.AddItem CL.Offset(-n, 0)

    UserForm1.owncertificate.List(B, 1) = Format(CL.Value, "dd-mmm-yy")

    If CL >= Date - 5000 And CL <= Date + 90 Then

    c = CL - Date

    UserForm1.underexpiration.AddItem CL.Offset(-n, 0)

    UserForm1.underexpiration.List(a, 1) = Format(CL.Value, "dd-mmm-yy")

    UserForm1.underexpiration.List(a, 2) = c

    End If

    Exit For

    End If

    Next

    Next

    Call confronta.confronta

    Dim f As String, miapath As String

    n = UserForm1.crew.ListIndex

    X = UserForm1.crew.List(n, 1)

    miapath = Sheets("Expats").Range("BA1") & ""

    f = Dir(miapath & X & ".jpg")

    If f = "" Then

    UserForm1.foto.Picture = LoadPicture(Range("BA1") & "" & "immagine.bmp")

    Else

    UserForm1.foto.Picture = LoadPicture(miapath & f)

    End If

    End Sub

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2016-06-23T17:35:20+00:00

    Ho apportato le modifiche che hanno comportato un po' "stravolgimento" rispetto alla cartella di lavoro precedente un po' per capirmi meglio io :-) e un po' per fare in modo che se il codice dovesse essere letto da terzi non italiani forse potrebbe risultare più comprensibile. Per quanto non so se sono riuscito a raggiungere questo obiettivo :-)

    Questo il link: File esempio #6

    Ho aggiunto i due fogli realtivi alla Technical Crew e ai relativi Certtificate e ho rinominato i fogli (e quindi anche i nomi indicati nelle dichiarazionio costanti iniziali).

    • Maritime Crew
    • Maritime Certificate
    • Technical Crew
    • Technical Certificate

    Poiché la ListBox destinata a contenere i nominativi ora non è più relativa ai soli maritime l'ho rinominata, più genericamente, LB_Crew.

    Per gestire il diverso caricamento di dati ho quindi creato due distinte procedure che vengono richiamate in base alla TabStrip selezionata (LoadMaritimeCrew e LoadTechnicalCrew).

    Ho anche modificato il nome di alcune variabili nella speranza che rendano più compresibile lo scopo a cui sono destinate (un paio ora hanno un nome assolutamente "verboso" :-)).

    Ho modificato le descrizioni che vengono inserite in caso di certificati obbligatori scaduti inserendo in luogo del numero di giorni negativo il testo "Expirate!". Mentre se mancano meno di 90gg e fino all'ultimo giorno inserisce il numero di giorni mancanti.

    Per i certificati obbligatori senza data ho ripetuto due volte il testo "To be done!". Mi è sembrato che così colpisse più all'occhio.

    Ovviamente, se la soluzione non ti piacesse, ti basterebbe andare ad modificare le righe di comando dove trovi il testo "Expired!" e "To be done!" per ripristinare alla situazione precedente.

    Ho creato delle costanti dove ho inserito i parametri per le larghezze delle colonne delle ListBox e le ho assegnate alle rispettive proprietà ColumnWidths.

    In questo modo ti sarà più agevole modificare i parametri in base alle misure effettive delle tue listbox.

    Ho anche impostato che nelle LB_Mandatory e LB_Racommended compaia il ControlTipText della ListBox nel caso gli ultimi 4 caratteri nelle intestazioni di Certificate siano composte da "(1*)" (fino al 5 ma ovviamente da te replicabile in base ad esigenza).

    Tieni presente che se la nota è presente nelle intestazioni dei fogli Certificate, Maritime o Technical, dovranno essere presenti nelle intestazioni dei fogli Crew (altrimenti nella fase di confronto tra le intestazioni presenti nel foglio Crew con quelle presenti nel foglio Certificate non troverebbe la corrispondenza).

    Provando un po' non è che mi piaccia molto il comportamento del ControlTipText. Va bene quando selezioni la prima volta una riga con la "nota". Se però poi ne selezioni una diversa, sempre rimanendo all'interno della ListBox" per vedere il nuoto testo occorre spostare il puntatore del mouse fuori dalla listbox e poi rientrare.

    Ma volendo al posto dell'impstazione del ControlTipText puoi far comparire dei MsgBox con il testo legato alla relativa nota.

    Mi pare di aver riepilogato le modifiche, spero in maniera completa :-)

    Ora a te l'onere di testare il tutto :-)

    Riporto anche tutto il codice come modificato e integrato (tutto contenuto sempre nella UserForm2):

    '---

    Option Explicit

    '<--- costanti relative ai fogli di lavoro --->

    Const sNameWs1 As String = "Maritime Crew" 'Personale marittimo

    Const sWs1Rng1 As String = "A1"

    Const sNameWs2 As String = "Maritime Certificate" 'Corsi personale marittimo

    Const sWs2Rng1 As String = "A1"

    Const sNameWs3 As String = "Technical Crew" 'Personale tecnico

    Const sWs3Rng1 As String = "A1"

    Const sNameWs4 As String = "Technical Certificate" 'Corsi Personale tecnico

    Const sWs4Rng1 As String = "A1"

    '<--- constanti larghezza colonne delle ListBox --->

    Const sColWidthLB_MaritimeCrew As String = "2,5 cm;5 cm;1,5 cm"

    Const sColWidthLB_ThechnicalCrew As String = "3,5 cm;5,5 cm"

    Const sColWidthLB_CertificateOnBoard As String = "13,75 cm;1,5 cm"

    Const sColWidthLB_CertificateExpired As String = "10,75 cm;3 cm;2 cm"

    '<--- dichiarazioni variabili relative ai fogli di lavoro --->

    Dim Wb As Workbook

    Dim Ws1 As Worksheet

    Dim Ws1Rng1 As Range

    Dim CR1 As Range

    Dim NumRowCR1 As Integer

    Dim NumColumnCR1 As Integer

    Dim Ws2 As Worksheet

    Dim Ws2Rng1 As Range

    Dim CR2 As Range

    Dim NumRowCR2 As Integer

    Dim NumColumnCR2 As Integer

    Dim Ws3 As Worksheet

    Dim Ws3Rng1 As Range

    Dim CR3 As Range

    Dim NumRowCR3 As Integer

    Dim NumColumnCR3 As Integer

    Dim Ws4 As Worksheet

    Dim Ws4Rng1 As Range

    Dim CR4 As Range

    Dim NumRowCR4 As Integer

    Dim NumColumnCR4 As Integer

    '<--- variabile per data odierna --->

    Dim Today As Date

    Private Sub UserForm_Initialize()

      '<--- dichiarazioni variabili e impostazioni array intestazioni ListBox --->

      Dim sLB_Header_Crew As Variant

      Dim sLB_Header_CertificateOnBoard As Variant

      Dim sLB_Header_CertificateExpired As Variant

      sLB_Header_Crew = Array("Rank", "Surname & Name", "Badge Nr")

      sLB_Header_CertificateOnBoard = Array("Certificate Type", "Expiring Date")

      sLB_Header_CertificateExpired = Array("Certificate Type", "Expiring Date", "Day Left")

      '<--- Impostazioni Workbook, Worksheets e Range --->

      Set Wb = ThisWorkbook

      With Wb

        '<--- WorkSheet Maritime Crew --->

        Set Ws1 = .Worksheets(sNameWs1)

        Set Ws1Rng1 = Ws1.Range(sWs1Rng1)

        Set CR1 = Ws1Rng1.CurrentRegion

        NumRowCR1 = CR1.Rows.Count

        NumColumnCR1 = CR1.Columns.Count

        '<--- WorkSheet Maritime Certificate --->

        Set Ws2 = .Worksheets(sNameWs2)

        Set Ws2Rng1 = Ws2.Range(sWs2Rng1)

        Set CR2 = Ws2Rng1.CurrentRegion

        NumRowCR2 = CR2.Rows.Count

        NumColumnCR2 = CR2.Columns.Count

        '<--- WorkSheet Technical Crew --->

        Set Ws3 = .Worksheets(sNameWs3)

        Set Ws3Rng1 = Ws3.Range(sWs3Rng1)

        Set CR3 = Ws3Rng1.CurrentRegion

        NumRowCR3 = CR3.Rows.Count

        NumColumnCR3 = CR3.Columns.Count

        '<--- WorkSheet Technical Certificate --->

        Set Ws4 = .Worksheets(sNameWs4)

        Set Ws4Rng1 = Ws4.Range(sWs4Rng1)

        Set CR4 = Ws4Rng1.CurrentRegion

        NumRowCR4 = CR4.Rows.Count

        NumColumnCR4 = CR4.Columns.Count

      End With

      '<--- memorizzo la data odierna --->

      Today = Date

      '<--- impostazioni iniziali ListBox --->

      With Me

        .TabStrip1.Value = 0

        With .LB_Crew

          .List() = CR1.Offset(1, 0).Resize(NumRowCR1 - 1, 3).Value

          .ColumnCount = 3

          .ColumnWidths = sColWidthLB_MaritimeCrew

        End With

        With .LB_Header_Crew

          .Column() = sLB_Header_Crew

          .ColumnCount = 3

          .ColumnWidths = sColWidthLB_MaritimeCrew

        End With

        With .LB_CertificateOnBoard

          .ColumnCount = 2

          .ColumnWidths = sColWidthLB_CertificateOnBoard

        End With

        With .LB_Header_CertificateOnBoard

          .Column() = sLB_Header_CertificateOnBoard

          .ColumnCount = 2

          .ColumnWidths = sColWidthLB_CertificateOnBoard

        End With

        With .LB_CertificateExpired

          .ColumnCount = 3

          .ColumnWidths = sColWidthLB_CertificateExpired

        End With

        With .LB_Header_CertificateExpired

          .Column() = sLB_Header_CertificateExpired

          .ColumnCount = 3

          .ColumnWidths = sColWidthLB_CertificateExpired

        End With

      End With

    End Sub

    Private Sub LB_Crew_Click()

      With Me

        If .TabStrip1.Value = 0 Then

          Call LoadMaritimeCrew

        ElseIf .TabStrip1.Value = 1 Then

          Call LoadTechnicalCrew

        End If

        .LB_Mandatory.ControlTipText = Empty

        .LB_Racommended.ControlTipText = Empty

      End With

    End Sub

    Private Sub LB_Mandatory_Click()

      With Me

        With .LB_Mandatory

          Select Case Right(.List(.ListIndex), 4)

            Case "(1*)"

             .ControlTipText = "Nota " & "(1*)"

            Case "(2*)"

             .ControlTipText = "Nota " & "(2*)"

            Case "(3*)"

             .ControlTipText = "Nota " & "(3*)"

            Case "(4*)"

             .ControlTipText = "Nota " & "(4*)"

            Case "(5*)"

             .ControlTipText = "Nota " & "(5*)"

            Case Else

             .ControlTipText = Empty

          End Select

        End With

      End With

    End Sub

    Private Sub LB_Racommended_Click()

      With Me

        With .LB_Racommended

          Select Case Right(.List(.ListIndex), 4)

            Case "(1*)"

             .ControlTipText = "Nota " & "(1*)"

            Case "(2*)"

             .ControlTipText = "Nota " & "(2*)"

            Case "(3*)"

             .ControlTipText = "Nota " & "(3*)"

            Case "(4*)"

             .ControlTipText = "Nota " & "(4*)"

            Case "(5*)"

             .ControlTipText = "Nota " & "(5*)"

            Case Else

             .ControlTipText = Empty

          End Select

        End With

      End With

    End Sub

    Private Sub TabStrip1_Change()

      Dim sLB_Header_Crew As Variant

      With Me

        If .TabStrip1.Value = 0 Then

          Call ClearListBox

            With .LB_Crew

              .List() = CR1.Offset(1, 0).Resize(NumRowCR1 - 1, 3).Value

              .ColumnCount = 3

              .ColumnWidths = sColWidthLB_MaritimeCrew

            End With

            With .LB_Header_Crew

                sLB_Header_Crew = Array("Rank", "Surname & Name", "Badge Nr")

                .ColumnCount = 3

                .Column() = sLB_Header_Crew

                .ColumnWidths = sColWidthLB_MaritimeCrew

            End With

        ElseIf .TabStrip1.Value = 1 Then

          Call ClearListBox

            With .LB_Crew

              .List() = CR3.Offset(1, 0).Resize(NumRowCR3 - 1, 2).Value

              .ColumnCount = 2

              .ColumnWidths = sColWidthLB_ThechnicalCrew

            End With

            With .LB_Header_Crew

                sLB_Header_Crew = Array("Rank", "Surname & Name")

                .ColumnCount = 2

                .Column() = sLB_Header_Crew

                .ColumnWidths = sColWidthLB_ThechnicalCrew

            End With

        End If

      End With

    End Sub

    Private Sub LoadMaritimeCrew()

      Dim sJobTitle As String

      Dim sCrewName As String

      Dim FindCertificateFromWsCertificate As Range

      Dim FindCertificateFromWsCrew As Range

      Dim i As Integer, t As Integer

      Call ClearListBox

      With Me

      With .LB_Crew

        sJobTitle = .List(.ListIndex, 0)

        sCrewName = .List(.ListIndex, 1)

      End With

      Set FindCertificateFromWsCertificate = CR2.Resize(NumRowCR2, 1).Find(What:=sJobTitle, _

                                                                           After:=Ws2Rng1, _

                                                                           LookIn:=xlValues, _

                                                                           LookAt:=xlWhole, _

                                                                           SearchOrder:=xlByRows)

      Set FindCertificateFromWsCrew = CR1.Resize(NumRowCR1, 1).Offset(0, 1).Find(What:=sCrewName, _

                                                                                 After:=Ws1Rng1.Offset(0, 1), _

                                                                                 LookIn:=xlValues, _

                                                                                 LookAt:=xlWhole, _

                                                                                 SearchOrder:=xlByRows)

        For i = 1 To NumColumnCR2 - 1

          If Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "M" Then

            .LB_Mandatory.AddItem Ws2Rng1.Offset(0, i).Value

          End If

          If Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "R" Then

            .LB_Racommended.AddItem Ws2Rng1.Offset(0, i).Value

          End If

            For t = 1 To NumColumnCR1 - 3

              If Ws1Rng1.Offset(0, t + 2).Value = Ws2Rng1.Offset(0, i).Value Then

                If FindCertificateFromWsCrew.Offset(0, t + 1).Value <> "" Then

                  If IsDate(FindCertificateFromWsCrew.Offset(0, t + 1).Value) And _

                     Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "M" Then

                    If FindCertificateFromWsCrew.Offset(0, t + 1).Value > Today + 90 Then

                      With .LB_CertificateOnBoard

                        .AddItem

                        .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                        .List(.ListCount - 1, 1) = FindCertificateFromWsCrew.Offset(0, t + 1).Value

                      End With

                    Else

                      With .LB_CertificateExpired

                        .AddItem

                        .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                        .List(.ListCount - 1, 1) = FindCertificateFromWsCrew.Offset(0, t + 1).Value

                        If FindCertificateFromWsCrew.Offset(0, t + 1).Value - Today > 0 Then

                          .List(.ListCount - 1, 2) = FindCertificateFromWsCrew.Offset(0, t + 1).Value - Today

                        Else

                         .List(.ListCount - 1, 2) = "Expired!"

                        End If

                      End With

                    End If

                  Else

                      With .LB_CertificateOnBoard

                        .AddItem

                        .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                        .List(.ListCount - 1, 1) = FindCertificateFromWsCrew.Offset(0, t + 1).Value

                      End With

                  End If

                Else

                  If Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "M" Then

                    With .LB_CertificateExpired

                      .AddItem

                      .List(.ListCount - 1, 0) = Ws1Rng1.Offset(0, t + 2).Value

                      .List(.ListCount - 1, 1) = "To be done!"

                      .List(.ListCount - 1, 2) = "To be done!"

                    End With

                  End If

                End If

              End If

            Next t

        Next i

      End With

    End Sub

    Private Sub LoadTechnicalCrew()

      Dim sJobTitle As String

      Dim sCrewName As String

      Dim FindCertificateFromWsCertificate As Range

      Dim FindCertificateFromWsCrew As Range

      Dim i As Integer, t As Integer

      Call ClearListBox

      With Me

      With .LB_Crew

        sJobTitle = .List(.ListIndex, 0)

        sCrewName = .List(.ListIndex, 1)

      End With

      Set FindCertificateFromWsCertificate = CR4.Resize(NumRowCR4, 1).Find(What:=sJobTitle, _

                                                                           After:=Ws4Rng1, _

                                                                           LookIn:=xlValues, _

                                                                           LookAt:=xlWhole, _

                                                                           SearchOrder:=xlByRows)

      Set FindCertificateFromWsCrew = CR3.Resize(NumRowCR3, 1).Offset(0, 1).Find(What:=sCrewName, _

                                                                                 After:=Ws3Rng1.Offset(0, 1), _

                                                                                 LookIn:=xlValues, _

                                                                                 LookAt:=xlWhole, _

                                                                                 SearchOrder:=xlByRows)

        For i = 1 To NumColumnCR4 - 1

          If Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "M" Then

            .LB_Mandatory.AddItem Ws4Rng1.Offset(0, i).Value

          End If

          If Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "R" Then

            .LB_Racommended.AddItem Ws4Rng1.Offset(0, i).Value

          End If

            For t = 1 To NumColumnCR3 - 2

              If Ws3Rng1.Offset(0, t + 1).Value = Ws4Rng1.Offset(0, i).Value Then

                If FindCertificateFromWsCrew.Offset(0, t).Value <> "" Then

                  If IsDate(FindCertificateFromWsCrew.Offset(0, t).Value) And _

                     Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "M" Then

                    If FindCertificateFromWsCrew.Offset(0, t).Value > Today + 90 Then

                      With .LB_CertificateOnBoard

                        .AddItem

                        .List(.ListCount - 1, 0) = Ws3Rng1.Offset(0, t + 1).Value

                        .List(.ListCount - 1, 1) = FindCertificateFromWsCrew.Offset(0, t).Value

                      End With

                    Else

                      With .LB_CertificateExpired

                        .AddItem

                        .List(.ListCount - 1, 0) = Ws3Rng1.Offset(0, t + 1).Value

                        .List(.ListCount - 1, 1) = FindCertificateFromWsCrew.Offset(0, t).Value

                        If FindCertificateFromWsCrew.Offset(0, t).Value - Today > 0 Then

                          .List(.ListCount - 1, 2) = FindCertificateFromWsCrew.Offset(0, t).Value - Today

                        Else

                         .List(.ListCount - 1, 2) = "Expired!"

                        End If

                      End With

                    End If

                  Else

                      With .LB_CertificateOnBoard

                        .AddItem

                        .List(.ListCount - 1, 0) = Ws3Rng1.Offset(0, t + 1).Value

                        .List(.ListCount - 1, 1) = FindCertificateFromWsCrew.Offset(0, t).Value

                      End With

                  End If

                Else

                  If Left(UCase(FindCertificateFromWsCertificate.Offset(0, i).Value), 1) = "M" Then

                    With .LB_CertificateExpired

                      .AddItem

                      .List(.ListCount - 1, 0) = Ws3Rng1.Offset(0, t + 1).Value

                      .List(.ListCount - 1, 1) = "To be done!"

                      .List(.ListCount - 1, 2) = "To be done!"

                    End With

                  End If

                End If

              End If

            Next t

        Next i

      End With

    End Sub

    Private Sub ClearListBox()

      With Me

        .LB_Mandatory.Clear

        .LB_Racommended.Clear

        .LB_CertificateOnBoard.Clear

        .LB_CertificateExpired.Clear

      End With

    End Sub

    '----

    La risposta è stata utile?

    0 commenti Nessun commento