ECCEZZIONE NON GESTITA



  • ECCEZZIONE NON GESTITA
    di twddesign (utente non iscritto) data: 24/06/2015 20:00:57

    ciao a tutti, devo conteggiare dei team presenti alle gare.
    praticamente sono tutti incolonnati ma capita spesso che ci siano celle vuote
    ed il conteggio salta e non conteggia esattamente tutte le occorrenze.
    se riempio le celle anche con 0, il conteggio esatto va a buon fine.
    come gestire questa eccezzione in caso trova una cella vuota continua a conteggiare le occorrenze?
    Grazie a tutti
     
    Private Sub Classifica_Click()
    Dim arry(1 To 1000, 1 To 2) As String
    
    For a = 2 To 1000
        If Worksheets("Iscrizioni").Cells(a, 9) <> "" Then
        
            team = Worksheets("Iscrizioni").Cells(a, 9)
            
            For b = 1 To 500
                If arry(b, 1) <> "" Then
                    If arry(b, 1) = team Then
                         arry(b, 2) = arry(b, 2) + 1
                         Exit For
                    End If
                Else
                arry(b, 1) = team
                totale = arry(b, 2)
                If totale = "" Then totale = 0
                arry(b, 2) = totale + 1
                Exit For
            End If
            Next
        Else
            Exit For
        End If
    Next
    
    
    For b = 1 To 999
    If arry(b, 1) <> "" Then
    team = arry(b, 1)
    maxim = CInt(arry(b, 2))
        For a = b + 1 To 1000
        If arry(a, 1) <> "" Then
                If maxim < CInt(arry(a, 2)) Then
                    tempteam = arry(a, 1)
                    tempscore = arry(a, 2)
                    arry(a, 1) = arry(b, 1)
                    arry(a, 2) = arry(b, 2)
                    arry(b, 1) = tempteam
                    arry(b, 2) = tempscore
                    team = arry(b, 1)
                    maxim = CInt(arry(b, 2))
                End If
        Else
            Exit For
        End If
        Next
    Else
        Exit For
    End If
        conta = conta + 1
        Worksheets("10_TEAM_PRESENTI").Cells(2 + conta, 10) = arry(b, 1)
        Worksheets("10_TEAM_PRESENTI").Cells(2 + conta, 12) = arry(b, 2)
    Next
    End Sub
    
    



  • di totygno71 data: 24/06/2015 20:44:17

    Una domanda...
    Hai scritto tu il codice?


  • ECCEZZIONE NON GESTITA
    di twddesign (utente non iscritto) data: 24/06/2015 20:50:11

    no



  • di totygno71 data: 24/06/2015 21:07:32

    ah ecco...
    Le EcceZZioni ^_^ andrebbero dichiarate nel momento in cui si descrive lo scenario altrimenti succedono questi imprevisti...
    Vediamo se chi ti ha scritto il codice (che quindi conosce il tutto) o qulacun altro (ma dovresti postare il file) riesce a gestire anche questa ecceZione!
    Toty


  • ECCEZZIONE NON GESTITA
    di twddesign (utente non iscritto) data: 27/06/2015 15:31:12

    ecco il file..
    praticamente se sta qualche cella vuota
    non miconteggia bene i team presenti.



  • di totygno71 data: 28/06/2015 14:06:28

    Prova così... ho solo tolto un exit for.. nel ciclo for a =2 to 1000
    Ciao
     
    Private Sub Classifica_Click()
    Dim arry(1 To 1000, 1 To 2) As String
    
    For a = 2 To 1000
        If Worksheets("Iscrizioni").Cells(a, 9) <> "" Then
        
            team = Worksheets("Iscrizioni").Cells(a, 9)
            
            For b = 1 To 500
                If arry(b, 1) <> "" Then
                    If arry(b, 1) = team Then
                         arry(b, 2) = arry(b, 2) + 1
                         Exit For
                    End If
                Else
                arry(b, 1) = team
                totale = arry(b, 2)
                If totale = "" Then totale = 0
                arry(b, 2) = totale + 1
                Exit For
                End If
            Next
        End If
    Next
    
    
    For b = 1 To 999
    If arry(b, 1) <> "" Then
    team = arry(b, 1)
    maxim = CInt(arry(b, 2))
        For a = b + 1 To 1000
        If arry(a, 1) <> "" Then
                If maxim < CInt(arry(a, 2)) Then
                    tempteam = arry(a, 1)
                    tempscore = arry(a, 2)
                    arry(a, 1) = arry(b, 1)
                    arry(a, 2) = arry(b, 2)
                    arry(b, 1) = tempteam
                    arry(b, 2) = tempscore
                    team = arry(b, 1)
                    maxim = CInt(arry(b, 2))
                End If
        Else
            Exit For
        End If
        Next
    Else
        Exit For
    End If
        conta = conta + 1
        Worksheets("10_TEAM_PRESENTI").Cells(2 + conta, 10) = arry(b, 1)
        Worksheets("10_TEAM_PRESENTI").Cells(2 + conta, 12) = arry(b, 2)
    Next
    End Sub
    



  • di Traniwebdesign data: 28/06/2015 14:15:25

    perfetto sembra funzionare alla grande..



  • di Traniwebdesign data: 28/06/2015 14:18:48

    posso esporre un altro problema ?



  • di totygno71 data: 28/06/2015 14:22:07

    Non è vietato esporre i propri problemi altrimenti cosa esisterebbe a fare il forum???


  • ECCEZZIONE NON GESTITA
    di Traniwebdesign data: 28/06/2015 15:18:19

    ho questa macro che mi sostituisci una riga con un altra riga.
    mi sostituitsce tutte le celle che vanno dalla lettera B alla lettera L.....se io volessi far fermare la sostituzione fino alla lettera J ? cio 2 celle prima ?
     
    Sub trova()
    Dim ma()
    Dim pos1, pos2, c, i As Long
    Dim fin1, fin2 As Range
    ReDim ma(0)
    pos1 = InputBox("Inserire il corridore 1: ")
    pos2 = InputBox("Inserire il corridore 2: ")
    If pos1 <> "" And pos2 <> "" Then
        Set fin1 = Columns(2).Find(What:=pos1, LookAt:=xlWhole)
        Set fin2 = Columns(2).Find(What:=pos2, LookAt:=xlWhole)
        If Not fin1 Is Nothing And Not fin2 Is Nothing Then
            c = Cells(1, Columns.Count).End(xlToLeft).Column
            For i = 2 To c
                ma(UBound(ma)) = Cells(fin1.Row, i)
                ReDim Preserve ma(UBound(ma) + 1)
            Next
            Range(Cells(fin1.Row, 2), Cells(fin1.Row, c)) = Range(Cells(fin2.Row, 2), Cells(fin2.Row, c)).Value
            For i = 1 To UBound(ma)
                Cells(fin2.Row, i + 1) = ma(i - 1)
            Next
        Else
            MsgBox "Corridori non trovati."
        End If
    Else
        MsgBox "Valori non validi."
    End If
    End Sub


  • ECCEZZIONE NON GESTITA
    di Traniwebdesign data: 28/06/2015 15:23:50

    nel foglio DAGSV c'è la macro che inverte..........
    ora vorrei che continuasse a funzionare cosi come è, ma la vorrei che mi si fermasse alla cella j invece che fermasri alla cella L.



  • di totygno71 data: 28/06/2015 16:04:37

    Prova così...
     
    Sub trova()
    Dim ma()
    Dim pos1, pos2, c, i As Long
    Dim fin1, fin2 As Range
    ReDim ma(0)
    pos1 = InputBox("Inserire il corridore 1: ")
    pos2 = InputBox("Inserire il corridore 2: ")
    If pos1 <> "" And pos2 <> "" Then
        Set fin1 = Columns(2).Find(What:=pos1, LookAt:=xlWhole)
        Set fin2 = Columns(2).Find(What:=pos2, LookAt:=xlWhole)
        If Not fin1 Is Nothing And Not fin2 Is Nothing Then
            c = 9
            For i = 2 To c
                ma(UBound(ma)) = Cells(fin1.Row, i)
                ReDim Preserve ma(UBound(ma) + 1)
            Next
            Range(Cells(fin1.Row, 2), Cells(fin1.Row, c)) = Range(Cells(fin2.Row, 2), Cells(fin2.Row, c)).Value
            For i = 1 To UBound(ma)
                Cells(fin2.Row, i + 1) = ma(i - 1)
            Next
        Else
            MsgBox "Corridori non trovati."
        End If
    Else
        MsgBox "Valori non validi."
    End If
    End Sub
    



  • di totygno71 data: 28/06/2015 16:12:42

    Immagino che anche questo codice non sia farina del tuo sacco quindi non posso criticarti il metodo che si è usato per ottenere il risultato voluto.


  • ECCEZZIONE NON GESTITA
    di Traniwebdesign data: 28/06/2015 16:15:14

    no non è farina del mio sacco, ma puoi criticarlo se alla fine è d iaiuto a tutti quanti è costruttivo.



  • di totygno71 data: 28/06/2015 16:19:50

    Era quello che volevi ottenere?


  • ECCEZZIONE NON GESTITA
    di Traniwebdesign data: 28/06/2015 16:22:23

    GRAZIE cmq dell'aiuto che mi dai..sei veramente gentilissimo.
    Ora ho un ultimo problema.
    quando apro il file, praticamente il file richiede un altro file csv che gli do in pasto ogni volta;
    bene il file richiesto è la tempistica dei corridori.e questa tempistica è incrementale, nel senso che
    ES. alle 12 sono arrivati 100 corridori.........poi alle 12.10 ne sono arrivati 120.....
    ora se io mi metto a modificare il foglio dagsv ed elimino qualcosa o sposto qualcosa e vado a reimportare gli altri arrivi tutto il mio lavoro va a farsi benedire....
    Esiste un modo per caricare solo i corridori non presenti gia nel foglio dsgsv ? tipo vede che l'ultimo ha il pettorale 81......e va ad aggiungere da li in poi...




  • di totygno71 data: 28/06/2015 16:24:17

    Direi che per ogni problema devi aprire una discussione nuova, quindi gentilmente spunta su Risolta la discussione e aprine una nuova con il nuovo quesito.
    Ciao Toty