Search code examples
excelvbaselectcase

Problem with Case Select is too slow after 35 variables


I currently running a case select depending on the value of a cell to set different cells to "NA" (its a data entry sheet) , depending on this string I have currently like 35 options to check for the case select, and it's too slow, taking like 5 minutes to search

the code goes like this

  Dim rng As Range
    Dim cell As Range
    Dim rw As Long

'   See if any cells updated in column H (dropdown list)
    
    Set rng = Intersect(Target, Range("H:H"))
    
    If rng Is Nothing Then Exit Sub

    Application.EnableEvents = False

'   Loop through updated cells in columns I (Merge cell with combination)
    'For Each cell In rng
    For Each cell In Range("I:I")
        rw = cell.Row
        Select Case cell.Value
        
        Case "LocalElaboração_DossiêCancelamento de Registro", "LocalElaboração_DossiêCumprimento de Exigência", "LocalElaboração_DossiêDescontinuação Temporária/ Definitiva", "LocalElaboração_DossiêDesistência a pedido", "LocalElaboração_DossiêPós-registro - Notificação simplificada", "LocalElaboração_DossiêReativação de Manufatura", "LocalElaboração_DossiêRecurso", "LocalElaboração_DossiêRegistro", "LocalElaboração_DossiêRenovação", "LocalElaboração_DossiêRetificação de Publicação", "LocalElaboração_DossiêTransferência de Titularidade", "LocalElaboração_DossiêPós-registro - Paralelas", "LocalElaboração_DossiêPós-registro", "LocalElaboração_DossiêPós-registro - Concomitante", "LocalElaboração_DossiêPós-registro - Simultâneas"
            Cells(rw, "O") = "NA"
            Cells(rw, "R") = "NA"
            Cells(rw, "S") = "NA"
            Cells(rw, "U") = "NA"
            Cells(rw, "V") = "NA"
            Cells(rw, "W") = "NA"
            Cells(rw, "X") = "NA"
            Cells(rw, "Y") = "NA"
            Cells(rw, "Z") = "NA"
            Cells(rw, "AA") = "NA"
            Cells(rw, "AB") = "NA"
            Cells(rw, "AD") = "NA"
            Cells(rw, "AL") = "NA"
            Cells(rw, "AM") = "NA"
            Cells(rw, "AN") = "NA"
            Cells(rw, "AP") = "NA"
            Cells(rw, "AQ") = "NA"
            Cells(rw, "AR") = "NA"
            Cells(rw, "AT") = "NA"
            Cells(rw, "AU") = "NA"

            Case "LocalSistemasVEEVA - Dispatch", "LocalSistemasVEEVA - Registration - Atualização", "LocalSistemasVEEVA - RO", "LocalElaboração_DossiêAvaliação de documentação", "LocalSistemasVeeva - Application"
            
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
            Case "LocalSistemasVEEVA - Commitment", "LocalSistemasVEEVA - Correção", "LocalSistemasVEEVA - Bundling", "LocalSistemasVEEVA - HMP", "LocalSistemasVEEVA - Registration - Criação", "LocalSistemasVEEVA - Submission"
                Cells(rw, "J") = "NA"
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                               
                
              Case "LocalPeticionamentoFuncionamento da empresa (AE e AFE)", "LocalPeticionamentoGMP - Certificação inicial", "LocalPeticionamentoGMP - Renovação", "LocalPeticionamentoGMP - Inclusão de produto em linha já certificada", "LocalPeticionamentoGMP - Inclusão de produto em linha já certificada", "LocalPeticionamentoPós-registro", "LocalPeticionamentoRegistro", "LocalPeticionamentoRetificação de Publicação", "LocalPeticionamentoRotulagem - Demandas DRA - Alteração", "LocalPeticionamentoRotulagem - Pós Registro - Alteração", "LocalPeticionamentoRPF/RMP"
               
  
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
               Case "LocalElaboração_DossiêPós-registro - HMP - INFO SUP", "LocalElaboração_DossiêPós-registro - HMP - Paralelas", "LocalElaboração_DossiêPós-registro - HMP - Concomitante", "LocalElaboração_DossiêPós-registro - protocolo - INFO SUP"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "T") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
               
             Case "LocalPeticionamentoAditamento", "LocalPeticionamentoBula - Revisão de Bula Padrão", "LocalPeticionamentoCumprimento de Exigência", "LocalPeticionamentoDesistência a pedido", "LocalPeticionamentoHMP - Pós-registro - Mudança Exclusiva de HMP", "LocalPeticionamentoRecurso", "LocalPeticionamentoRotulagem - Demandas DRA - Notificação", "LocalPeticionamentoRotulagem - Pós Registro  - Notificação", "LocalPeticionamentoSolicitação de correção de dados na base", "LocalPeticionamentoToken", "LocalPeticionamentoTransferência de Titularidade"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                               
            Case "LocalDesfechoPeticionamento - Renovação", "LocalDesfechoRenovação"
                Cells(rw, "O") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"

            Case "GlobalDesfechoCaixa Postal - Exigência", "GlobalDesfechoCaixa Postal - Ofício"
                Cells(rw, "J") = "NA"
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
            Case "GlobalDesfechoCBPF - Emissão Certificado", "GlobalDesfechoCBPF - Tradução de Certificado"
                Cells(rw, "J") = "NA"
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                                

             Case "LocalDOURevalidação automática", "LocalDOUAprovação condicional", "LocalDOUIndeferimento", "LocalDOUProrrogação do prazo de análise"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
             Case "LocalElaboração_DossiêBula - Pós Registro  - Notificação", "LocalElaboração_DossiêBula - Pós Registro - Alteração", "LocalElaboração_DossiêBula - CCDS/CCSI - Notificação"
             
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
             Case "LocalElaboração_DossiêHMP", "LocalElaboração_DossiêAditamento"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
                
            Case "LocalElaboração_DossiêRotulagem - Notificação", "LocalElaboração_DossiêRotulagem - Rotulário"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                

                

                

             Case "LocalPeticionamentoCancelamento de Registro", "LocalPeticionamentoDescontinuação Temporária/ Definitiva"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                


              Case "LocalRotulagem_ArtesVistalink", "LocalRotulagem_ArtesVistaVac"
               
                Cells(rw, "J") = "NA"
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "T") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                
              Case "LocalElaboração_DossiêPós-registro - HMP - Minor", "LocalElaboração_DossiêPós-registro - HMP - Simultâneas"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "T") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"

              Case "GlobalDesfechoCBPF - DOU"
               
                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"

              Case "LocalPeticionamentoRenovação de Produto"
               

                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
            Case "LocalPeticionamentoBula -CCDS / CCSI - Alteração"
            
                Cells(rw, "U") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
                
             Case "LocalPeticionamentoBula - Pós Registro - Alteração"
            
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"

            Case "LocalPeticionamentoReativação de Manufatura"

                Cells(rw, "O") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"

             Case "LocalDOUDeferimento"

                Cells(rw, "O") = "NA"
                Cells(rw, "R") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
               
            Case "LocalPeticionamentoHMP"
            

                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
      
            Case "LocalOutrosEmissão de taxa - Registro/ Pós-registro"
            
                Cells(rw, "P") = "NA"
                Cells(rw, "Q") = "NA"
                Cells(rw, "S") = "NA"
                Cells(rw, "T") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
     
            Case "LocalDesfechoPeticionamento - HMP"
            
                Cells(rw, "O") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
     
             Case "LocalDesfechoPeticionamento"
            
                Cells(rw, "O") = "NA"
                Cells(rw, "U") = "NA"
                Cells(rw, "V") = "NA"
                Cells(rw, "W") = "NA"
                Cells(rw, "X") = "NA"
                Cells(rw, "Y") = "NA"
                Cells(rw, "Z") = "NA"
                Cells(rw, "AA") = "NA"
                Cells(rw, "AB") = "NA"
                Cells(rw, "AD") = "NA"
                Cells(rw, "AF") = "NA"
                Cells(rw, "AG") = "NA"
                Cells(rw, "AH") = "NA"
                Cells(rw, "AI") = "NA"
                Cells(rw, "AJ") = "NA"
                Cells(rw, "AK") = "NA"
                Cells(rw, "AL") = "NA"
                Cells(rw, "AM") = "NA"
                Cells(rw, "AN") = "NA"
                Cells(rw, "AP") = "NA"
                Cells(rw, "AQ") = "NA"
                Cells(rw, "AR") = "NA"
                Cells(rw, "AT") = "NA"
                Cells(rw, "AU") = "NA"
            
           
            Case Else
'do nothing




        End Select
    Next cell
    
    Application.EnableEvents = True

End Sub

I have currently 35 variables but the sheet is too slow. Can someone help me out?. thx!!

My objective is to search for this combinations depending on the dropdown cell and type NA where applicable


Solution

  • A Worksheet Change: A Select Case Megalomania

    • This case was doubled:
      "LocalPeticionamentoGMP - Inclusao de produto em linha já certificada"

    Main

    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Const TOP_TARGET_CELL_ADDRESS As String = "H2"
        Const CHECK_COLUMN As String = "I"
        Const CHECK_REPLACEMENT_STRING As String = "NA"
        
        ' See if any cells updated in column 'H' (dropdown list).
        Dim irg As Range:
        With Me.Range(TOP_TARGET_CELL_ADDRESS)
            Set irg = Intersect(.Resize(Me.Rows.Count - .Row + 1), Target)
        End With
        If irg Is Nothing Then Exit Sub
    
        Dim urg As Range, rg As Range, cell As Range
        
        ' Loop through through the corresponding cells in column 'I'.
        For Each cell In Intersect(irg.EntireRow, Me.Columns(CHECK_COLUMN)).Cells
            Set rg = GetCombinedCells(CStr(cell.Value), cell.EntireRow)
            If Not rg Is Nothing Then
                If urg Is Nothing Then
                    Set urg = rg
                Else
                    Set urg = Union(urg, rg)
                End If
            End If
        Next cell
    
        If urg Is Nothing Then Exit Sub
        
        Application.EnableEvents = False
            urg.Value = CHECK_REPLACEMENT_STRING
        Application.EnableEvents = True
    
    End Sub
    

    Help

    Private Function GetCombinedCells(MatchString As String, rrg As Range) As Range
        Select Case MatchString
            Case "LocalElaboraçao_DossieCancelamento de Registro", _
                    "LocalElaboraçao_DossieCumprimento de Exigencia", _
                    "LocalElaboraçao_DossieDescontinuaçao Temporária/ Definitiva", _
                    "LocalElaboraçao_DossieDesistencia a pedido", _
                    "LocalElaboraçao_DossiePós-registro - Notificaçao simplificada", _
                    "LocalElaboraçao_DossieReativaçao de Manufatura", _
                    "LocalElaboraçao_DossieRecurso", _
                    "LocalElaboraçao_DossieRegistro", _
                    "LocalElaboraçao_DossieRenovaçao", _
                    "LocalElaboraçao_DossieRetificaçao de Publicaçao", _
                    "LocalElaboraçao_DossieTransferencia de Titularidade", _
                    "LocalElaboraçao_DossiePós-registro - Paralelas", _
                    "LocalElaboraçao_DossiePós-registro", _
                    "LocalElaboraçao_DossiePós-registro - Concomitante", _
                    "LocalElaboraçao_DossiePós-registro - Simultâneas"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalSistemasVEEVA - Dispatch", _
                    "LocalSistemasVEEVA - Registration - Atualizaçao", _
                    "LocalSistemasVEEVA - RO", _
                    "LocalElaboraçao_DossieAvaliaçao de documentaçao", _
                    "LocalSistemasVeeva - Application"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalSistemasVEEVA - Commitment", _
                    "LocalSistemasVEEVA - Correçao", _
                    "LocalSistemasVEEVA - Bundling", _
                    "LocalSistemasVEEVA - HMP", _
                    "LocalSistemasVEEVA - Registration - Criaçao", _
                    "LocalSistemasVEEVA - Submission"
                Set GetCombinedCells = rrg.Range("J1,O1,R1,S1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoFuncionamento da empresa (AE e AFE)", _
                    "LocalPeticionamentoGMP - Certificaçao inicial", _
                    "LocalPeticionamentoGMP - Renovaçao", _
                    "LocalPeticionamentoGMP - Inclusao de produto em linha já certificada", _
                    "LocalPeticionamentoGMP - Inclusao de produto em linha já certificada", _
                    "LocalPeticionamentoPós-registro", _
                    "LocalPeticionamentoRegistro", _
                    "LocalPeticionamentoRetificaçao de Publicaçao", _
                    "LocalPeticionamentoRotulagem - Demandas DRA - Alteraçao", _
                    "LocalPeticionamentoRotulagem - Pós Registro - Alteraçao", _
                    "LocalPeticionamentoRPF/RMP"
                Set GetCombinedCells = rrg.Range("U1,V1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalElaboraçao_DossiePós-registro - HMP - INFO SUP", _
                    "LocalElaboraçao_DossiePós-registro - HMP - Paralelas", _
                    "LocalElaboraçao_DossiePós-registro - HMP - Concomitante", _
                    "LocalElaboraçao_DossiePós-registro - protocolo - INFO SUP"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoAditamento", _
                    "LocalPeticionamentoBula - Revisao de Bula Padrao", _
                    "LocalPeticionamentoCumprimento de Exigencia", _
                    "LocalPeticionamentoDesistencia a pedido", _
                    "LocalPeticionamentoHMP - Pós-registro - Mudança Exclusiva de HMP", _
                    "LocalPeticionamentoRecurso", _
                    "LocalPeticionamentoRotulagem - Demandas DRA - Notificaçao", _
                    "LocalPeticionamentoRotulagem - Pós Registro  - Notificaçao", _
                    "LocalPeticionamentoSolicitaçao de correçao de dados na base", _
                    "LocalPeticionamentoToken", _
                    "LocalPeticionamentoTransferencia de Titularidade"
                Set GetCombinedCells = rrg.Range("O1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalDesfechoPeticionamento - Renovaçao", _
                    "LocalDesfechoRenovaçao"
                Set GetCombinedCells = rrg.Range("O1,V1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "GlobalDesfechoCaixa Postal - Exigencia", _
                     "GlobalDesfechoCaixa Postal - Ofício"
                Set GetCombinedCells = rrg.Range("J1,O1,R1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "GlobalDesfechoCBPF - Emissao Certificado", _
                    "GlobalDesfechoCBPF - Traduçao de Certificado"
                Set GetCombinedCells = rrg.Range("J1,O1,R1,U1,V1,W1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalDOURevalidaçao automática", _
                    "LocalDOUAprovaçao condicional", _
                    "LocalDOUIndeferimento", _
                    "LocalDOUProrrogaçao do prazo de análise"
                Set GetCombinedCells = rrg.Range("O1,R1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalElaboraçao_DossieBula - Pós Registro  - Notificaçao", _
                    "LocalElaboraçao_DossieBula - Pós Registro - Alteraçao", _
                    "LocalElaboraçao_DossieBula - CCDS/CCSI - Notificaçao"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,U1,V1,W1,X1,Y1,Z1,AA1,AT1,AU1")
            Case "LocalElaboraçao_DossieHMP", _
                    "LocalElaboraçao_DossieAditamento"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalElaboraçao_DossieRotulagem - Notificaçao", _
                    "LocalElaboraçao_DossieRotulagem - Rotulário"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AL1,AT1,AU1")
            Case "LocalPeticionamentoCancelamento de Registro", _
                    "LocalPeticionamentoDescontinuaçao Temporária/ Definitiva"
                Set GetCombinedCells = rrg.Range("O1,U1,V1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalRotulagem_ArtesVistalink", _
                    "LocalRotulagem_ArtesVistaVac"
                Set GetCombinedCells = rrg.Range("J1,O1,R1,T1,U1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1")
            Case "LocalElaboraçao_DossiePós-registro - HMP - Minor", _
                    "LocalElaboraçao_DossiePós-registro - HMP - Simultâneas"
                Set GetCombinedCells = rrg.Range("O1,R1,S1,T1,U1,V1,W1,X1,AA1,AB1,AD1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "GlobalDesfechoCBPF - DOU"
                Set GetCombinedCells = rrg.Range("O1,R1,U1,V1,W1,Y1,Z1,AA1,AB1,AD1,AL1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoRenovaçao de Produto"
                Set GetCombinedCells = rrg.Range("V1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoBula -CCDS / CCSI - Alteraçao"
                Set GetCombinedCells = rrg.Range("U1,X1,Y1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoBula - Pós Registro - Alteraçao"
                Set GetCombinedCells = rrg.Range("U1,V1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoReativaçao de Manufatura"
                Set GetCombinedCells = rrg.Range("O1,U1,V1,W1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalDOUDeferimento"
                Set GetCombinedCells = rrg.Range("O1,R1,V1,X1,Y1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalPeticionamentoHMP"
                Set GetCombinedCells = rrg.Range("V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalOutrosEmissao de taxa - Registro/ Pós-registro"
                Set GetCombinedCells = rrg.Range("P1,Q1,S1,T1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalDesfechoPeticionamento - HMP"
                Set GetCombinedCells = rrg.Range("O1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case "LocalDesfechoPeticionamento"
                Set GetCombinedCells = rrg.Range("O1,U1,V1,W1,X1,Y1,Z1,AA1,AB1,AD1,AF1,AG1,AH1,AI1,AJ1,AK1,AL1,AM1,AN1,AP1,AQ1,AR1,AT1,AU1")
            Case Else 'do nothing
        End Select
    End Function