Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di leomac
    Registrato dal
    Mar 2009
    Messaggi
    188

    [VB6] Velocizzare il codice

    Ragazzi salve,
    ho compilato il seguente codice:
    codice:
    Sub Casetto_Extra()
    ' Se le righe sono nascoste scoprile, se sono scoperte coprile
        If Rows("10:10").Hidden = True And Rows("54:54").Hidden = True _
            And Rows("98:98").Hidden = True And Rows("142:142").Hidden = True _
            And Rows("186:186").Hidden = True And Rows("230:230").Hidden = True _
            And Rows("274:274").Hidden = True And Rows("318:318").Hidden = True _
            And Rows("362:362").Hidden = True And Rows("406:406").Hidden = True _
            And Rows("450:450").Hidden = True And Rows("494:494").Hidden = True Then
                Rows("10:10").Hidden = False
                Rows("54:54").Hidden = False
                Rows("98:98").Hidden = False
                Rows("142:142").Hidden = False
                Rows("186:186").Hidden = False
                Rows("230:230").Hidden = False
                Rows("274:274").Hidden = False
                Rows("318:318").Hidden = False
                Rows("362:362").Hidden = False
                Rows("406:406").Hidden = False
                Rows("450:450").Hidden = False
                Rows("494:494").Hidden = False
        ElseIf Rows("10:10").Hidden = False And Rows("53:53").Hidden = False _
            And Rows("98:98").Hidden = False And Rows("142:142").Hidden = False _
            And Rows("186:186").Hidden = False And Rows("230:230").Hidden = False _
            And Rows("274:274").Hidden = False And Rows("318:318").Hidden = False _
            And Rows("362:362").Hidden = False And Rows("406:406").Hidden = False _
            And Rows("450:450").Hidden = False And Rows("494:494").Hidden = False Then
                Rows("10:10").Hidden = True
                Rows("54:54").Hidden = True
                Rows("98:98").Hidden = True
                Rows("142:142").Hidden = True
                Rows("186:186").Hidden = True
                Rows("230:230").Hidden = True
                Rows("274:274").Hidden = True
                Rows("318:318").Hidden = True
                Rows("362:362").Hidden = True
                Rows("406:406").Hidden = True
                Rows("450:450").Hidden = True
                Rows("494:494").Hidden = True
    End If
    End Sub
    in pratica una macro che nasconde/scopre diverse righe in excell.
    Dato che per far eseguire tutto il comando ci vogliono ben 3 sec, volevo sapere se c' era qualche modo per velocizzarlo.

    Grazie
    Ciaociao

  2. #2

    Re: [VB6] Velocizzare il codice

    Originariamente inviato da leomac
    ...........
    in pratica una macro che nasconde/scopre diverse righe in excell.
    Dato che per far eseguire tutto il comando ci vogliono ben 3 sec, volevo sapere se c' era qualche modo per velocizzarlo
    Mamma mia, che codice ! VVoVe:

    Suggerimenti:

    1) Puoi disabilitare l'aggiornamento su schermo, durante l'esecuzione della routine, premettendo Application.ScreenUpdating = False, e riportandolo a True alla fine.

    2) Visto che le righe sono visibili/invisibili "in blocco", fai il test SOLO su una riga !

    3) Usa Rows(10) anziche' Rows("10:10")

    4) anziche' una lunga sequenza di righe, potresti memorizzare la lista in un array
    codice:
    Dim r As Variant
    For Each r In Array(10, 54, 98 .......)
       Rows(r).Hidden = True
    Next





    P.S.: ....anche cosi' come l'hai postato tu, che ci metta 3 secondi mi pare proprio impossibile.... ma che PC hai ??
    IceCube_HT (VB6 fan Club)

  3. #3
    Utente di HTML.it L'avatar di leomac
    Registrato dal
    Mar 2009
    Messaggi
    188
    MITICO ICE!!
    ho risolto con apllication
    appena ho un pò di tempo lo modifico con l'arrey che hai consigliato ch'è più "semplice"
    codice:
    Sub Casetto_Extra()
    ' Se le righe sono nascoste scoprile, se sono scoperte coprile
        Application.ScreenUpdating = False
     If Rows("10:10").Hidden = True And Rows("54:54").Hidden = True _
            And Rows("98:98").Hidden = True And Rows("142:142").Hidden = True _
            And Rows("186:186").Hidden = True And Rows("230:230").Hidden = True _
            And Rows("274:274").Hidden = True And Rows("318:318").Hidden = True _
            And Rows("362:362").Hidden = True And Rows("406:406").Hidden = True _
            And Rows("450:450").Hidden = True And Rows("494:494").Hidden = True Then
                Rows("10:10").Hidden = False
                Rows("54:54").Hidden = False
                Rows("98:98").Hidden = False
                Rows("142:142").Hidden = False
                Rows("186:186").Hidden = False
                Rows("230:230").Hidden = False
                Rows("274:274").Hidden = False
                Rows("318:318").Hidden = False
                Rows("362:362").Hidden = False
                Rows("406:406").Hidden = False
                Rows("450:450").Hidden = False
                Rows("494:494").Hidden = False
        ElseIf Rows("10:10").Hidden = False And Rows("53:53").Hidden = False _
            And Rows("98:98").Hidden = False And Rows("142:142").Hidden = False _
            And Rows("186:186").Hidden = False And Rows("230:230").Hidden = False _
            And Rows("274:274").Hidden = False And Rows("318:318").Hidden = False _
            And Rows("362:362").Hidden = False And Rows("406:406").Hidden = False _
            And Rows("450:450").Hidden = False And Rows("494:494").Hidden = False Then
                Rows("10:10").Hidden = True
                Rows("54:54").Hidden = True
                Rows("98:98").Hidden = True
                Rows("142:142").Hidden = True
                Rows("186:186").Hidden = True
                Rows("230:230").Hidden = True
                Rows("274:274").Hidden = True
                Rows("318:318").Hidden = True
                Rows("362:362").Hidden = True
                Rows("406:406").Hidden = True
                Rows("450:450").Hidden = True
                Rows("494:494").Hidden = True 
    End If
    Application.ScreenUpdating = True
    End Sub
    non credo dipenda dal CPU quanto dalla marea di dati nel folgio d'excell...

    Ancora 1 volta slavato dal forum
    thx di cuore

  4. #4
    Originariamente inviato da leomac
    MITICO ICE!!
    ho risolto con apllication
    appena ho un pò di tempo lo modifico con l'arrey che hai consigliato ch'è più "semplice"
    non credo dipenda dal CPU quanto dalla marea di dati nel folgio d'excell...
    Puoi sostituire TUTTO quel... , semplicemente con:
    codice:
    Sub Invert()
       Dim r As Variant, s As Boolean
       Application.ScreenUpdating = False
       s = Rows(10).Hidden
       For Each r In Array(10, 54, 98, 142, 186, 230, 274, 318, 362, 406, 450, 
    494)
          Rows(r).Hidden = Not (s)
       Next
       Application.ScreenUpdating = True
    End Sub
    IceCube_HT (VB6 fan Club)

  5. #5
    Utente di HTML.it L'avatar di leomac
    Registrato dal
    Mar 2009
    Messaggi
    188
    A dire il vero ho risolto così:
    codice:
    Sub Casetto_Extra()
    Application.ScreenUpdating = False
    Dim Riga As Variant
    For Each Riga In Array(10, 54, 98, 142, 186, 230, 274, 318, 362, 406, 450, 494)
        If Rows(Riga).Hidden = True Then
            Rows(Riga).Hidden = False
        ElseIf Rows(Riga).Hidden = Flase Then
            Rows(Riga).Hidden = True
        End If
    Next
    Application.ScreenUpdating = True
    End Sub
    sarà che son fissato con le If...
    cmq thx lo stesso


  6. #6
    Originariamente inviato da leomac
    A dire il vero ho risolto così:
    codice:
    Sub Casetto_Extra()
    Application.ScreenUpdating = False
    Dim Riga As Variant
    For Each Riga In Array(10, 54, 98, 142, 186, 230, 274, 318, 362, 406, 450, 494)
        If Rows(Riga).Hidden = True Then
            Rows(Riga).Hidden = False
        ElseIf Rows(Riga).Hidden = Flase Then
            Rows(Riga).Hidden = True
        End If
    Next
    Application.ScreenUpdating = True
    End Sub
    sarà che son fissato con le If...
    cmq thx lo stesso

    Va' benissimo anche cosi' , e' forse piu' chiaro... io invece sono fissato con il codice piu' "corto" possibile...
    IceCube_HT (VB6 fan Club)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.