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-23T10:00:37+00:00

    Grande Casanmaner,

    tu mi fai le domande anticipate :)

    Quel 3 vicino la R sta a significare che ci sono dei commenti che in seguito vorrei far uscire quando seleziono il certificato da una delle due listbox che racchiudono sia gli obbligatori che i raccomandati. Quindi non so se si può fare con un codice che quando seleziono il certificato se esiste nella stringa di testo (3*) o (2*) ecc., i commenti sono solo 5, mi esce qualcosa tipo "ControlTipText" con visualizzato il commento oppure richiamare una messagebox.

    Grazie me lo stai facendo tu questo programma ;)

    Ciao

    Peppe

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2016-06-23T09:45:17+00:00

    Allora sono altri due distinti fogli. Uno per i nominativi (dove vedo che non è presente il campo Badge) e uno per gli specifici "corsi").

    Per quanto riguarda la tabstrip è lo stesso funzionamento (0,1).

    Cosa vuol dire quel R(3*)?

    E' da leggere comunque come R?

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2016-06-23T09:17:09+00:00

    Io sul file vecchio avevo inserito nell'evento tabstrip change che se era =0 cioè la prima voce mi caricava nella listbox con rowsource i nomi dal foglio1 cioè i marittimi, mentre se era =1 mi caricava i dati dal foglio2 cioè i tecnici avendo impostato il rowsource sfruttavo anche la proprietà columnheads.

    Adesso non so se si può applicare allo stesso modo anche qui.

    Ti allego le due schede dei tecnici ma il ragionamento è identico a quello dei marittimi.

    JOB TITLE SURNAME & NAME Basic Offshore Safety Induction And Emergency Training / FOET (1*) HUET (Helicopter Underwater Escape Training) H2S awareness (5*) Offshore Emergency Response Team Member (OERTM) / Refresher Offshore Emergency Response Team Leader (OERTL)  / Refresher Offshore Lifeboat Coxswain (Coxswain)  / Refresher Helicopter Landing Officer Initial Training (HLO) , then Helicopter Landing Officer Further Training (HLO FT) HLO Helideck Emergency Response Team Leader (HERTL) HDA Helideck Emergency Response Team Member (HERTM) Helideck Assistant Initial training, then <br><br>Helideck Assistant  Further training  (HDA FT) (2*) Helideck radio operator (CAA)
    Platform Manager DE MARCO FABRIZIO 15-lug-16
    Platform Manager ROSATI RAOUL 20-ott-17 15-ott-17
    Tour Pusher BALDI RENZO 27-feb-19 27-feb-19 10-mar-17
    Tour Pusher IALAZZO ANTONINO 28-ott-17 15-ott-17 10-mar-17
    Tour Pusher RACIOPPI DOMENICO 11-gen-20 16-gen-19 8-apr-17
    Tour Pusher FRANCIN DAMIR 29-ott-16 15-gen-15 21-apr-16
    Tour Pusher PACE LAURENCE 11-mar-20 1-feb-18 20-ott-16
    Tour Pusher SAVATOVIC OLIVER 14-gen-17 14-gen-15 14-ott-16
    Drilling Subsea Engineer DI BERARDINO LUCA 5-giu-18 5-giu-18 23-feb-13
    Drilling Subsea Engineer FONTANA CLAUDIO 1-mag-16 5-apr-16 4-nov-17
    Drilling Subsea Engineer PIANEZZE FIORENZO 25-feb-17 19-feb-17 12-nov-16
    Drilling Subsea Engineer ZELANDA MIRKO 22-giu-17
    Drilling Subsea Engineer MC KOWN MATTHEW 23-mag-17 10-ott-16 10-ott-14
    Drilling Subsea Engineer ROBERTSON LLOYD 11-nov-18 9-nov-18
    Driller VANZ MARTINO 17-gen-17 14-gen-15 9-mar-17
    Driller REID STEVEN 5-gen-18 24-mar-15 22-mar-17 10-giu-17
    Driller WYATT BRIAN 27-mar-17 28-mar-17 30-ott-17
    Driller trainer IMAM SUBEGJO 12-gen-19
    Driller trainer TONY IRAWAN 30-mar-19
    Assistant Driller ANDARIAS J. BENJAMIN 1-feb-20 11-apr-16 2-apr-14
    Assistant Driller DWIANTO 13-mar-16 16-giu-16
    Assistant Driller MUHAMMAD LILIEK SUDARTO 14-set-19 28-set-13 25-apr-14
    Assistant Driller MULYOHADI 14-set-19 28-set-13 25-gen-14
    Rig Chief Electrician CORTI FRANCESCO 9-set-17 9-lug-17 2-apr-18
    Rig Chief Electrician OLARU VASILICA 23-apr-20 5-mar-17 5-mar-17
    Rig Electrician PROVENZANO GIUSEPPE 24-ott-16 30-ago-16 30-ago-14
    Rig Electrician IURCIUC MARICEL 21-gen-18 10-dic-17 6-nov-16
    Rig Electrician HULA COSTANTIN ADRIAN 4-nov-16 30-ott-16 2-apr-18
    Rig Electrician PREVEDAN IGOR 19-giu-18 12-nov-16 12-nov-16
    Rig Electrician MARTA MUHARAM 31-ago-19 28-set-13 23-gen-16
    Rig Electrician PRAWITO 13-mag-18
    Rig Electrician HERLAMBANG WIBONO
    Rig Electrician WIDYASTONO 17-lug-16
    Rig Chief Mechanic SPECCHIA VINCENZO 8-apr-19 9-apr-19 27-giu-17
    Rig Chief Mechanic MAGNACCIA MASSIMO 29-apr-17 20-mar-17 2-lug-16
    Rig Chief Mechanic JAGODZIEWSKI DARIUSZ 26-mag-19 26-mag-17 19-feb-17
    Rig Chief Mechanic KOMOROSKI MIECZYSLAW 11-mar-16 18-gen-16 6-ago-17
    Rig Mechanic TADIC DAVID 18-feb-17 21-feb-19 21-feb-18
    Rig Mechanic TULUS SEJATI 23-apr-16
    Rig Mechanic BUDI DARLIS 3-gen-17
    Rig Mechanic AAN NOVAEKA SATRIA 3-apr-16
    JOB TITLE Basic Offshore Safety Induction And Emergency Training / FOET (1*) HUET (Helicopter Underwater Escape Training) H2S awareness (5*) Offshore Emergency Response Team Member (OERTM) / Refresher Offshore Emergency Response Team Leader (OERTL)  / Refresher Offshore Lifeboat Coxswain (Coxswain)  / Refresher Helicopter Landing Officer Initial Training (HLO) , then Helicopter Landing Officer Further Training (HLO FT) HLO Helideck Emergency Response Team Leader (HERTL) HDA Helideck Emergency Response Team Member (HERTM) Helideck Assistant Initial training, then <br><br>Helideck Assistant  Further training  (HDA FT) (2*) Helideck radio operator (CAA) GMDSS STCW A- IV/2 Dangerous Goods By Air (CAA)  / Refresher (3*) Helicopter Refueling  (HR) for vessels equipped with and using refueling system IWCF Level 2 IWCF Level 3 IWCF Level 4
    Platform Manager M M M M
    Tour Pusher M M M R M
    Drilling Subsea Engineer M M M R
    Driller M M M R M
    Driller trainer M M M R M
    Assistant Driller M M M R M
    Rig Chief Electrician M M M R
    Rig Electrician M M M R
    Rig Chief Mechanic M M M R
    Rig Mechanic M M M R
    Hydraulic Engineer Senior M M M R
    Hydraulic Engineer Junior M M M R
    Derrickman M M M R
    Assistant Derrickman M M M
    Floorman M M M
    Site Doctor M M M
    HSE Officer M M M R R R R
    Vessel Quality Coordinator Offshore Drilling M M M
    Electric and Electronic Lead M M M
    Electrical and Electronic Assistant M M M
    Turner/Lather M M M
    HVAC Supervisor M M M
    Crane Operator M M M R R R R R R R
    Steel Structural Carpenter M M M
    Helper M M M R R
    Painter M M M
    Storekeeper M M M
    Chief Storekeeper M M M R
    Store Distributor M M M
    Radio Operator M M M R R(3*)
    Purser M M M R R(3*)

    La risposta è stata utile?

    0 commenti Nessun commento