es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Variable de control siguiente no válido.

Me encuentro con un error “Error de compilación: variable de control Next no válida de referencia”.
Intentando saltar líneas de código si la variable no se encuentra en la hoja, por ejemplo, si X = 0 entonces salte. No puedo depurar paso a paso ya que salta directamente al error.

Agradezco cualquier ayuda o sugerencia.

Dim a Como Integer
Dim b Como Integer
Dim D Como Integer

‘ {…….}

‘ a
Freight_Str_Mínimo_Lista(1) = strFreightperMinCol:
Freight_Str_Mínimo_Lista(2) = strFreightMinCol:
Freight_Str_Mínimo_Lista(3) = strMOtherMinCol

‘ b
Freight_Col_Minimum_List (1) = FreightperMinCol:
Freight_Col_Minimum_List (2) = FreightMinCol:
Freight_Col_Minimum_List (3) = MOtherMinCol

‘ d
Freight_Str_PerKg_Lista(1) = strFreightperKgCol:
Freight_Str_PerKg_Lista(2) = strFreightperkgAll_InCol:
Freight_Str_PerKg_Lista(3) = strFreightless45All_InCol:
Freight_Str_PerKg_Lista(4) = strFreightgreater45All_InCol:
Freight_Str_PerKg_Lista(5) = strFreight100All_InCol:

‘ esto continúa hasta (9)

Para a = 1 a 3
Para b = 1 a 3
Para D = 1 a 9

Si Freight_Str_Minimum_Lista(a) = 0 Luego ir a nextsegment3
Si Freight_Col_Minimum_Lista(b) = 0 Luego ir a nextsegment3
Si Freight_Col_PerKg_List (D) = 0 Luego ir a nextsegment3

‘ líneas de código con cálculos con … end con

nextsegment3:
Siguiente a
Siguiente b
Siguiente D

Tags:  , ,

Answer

  1. Avatar for davy.ai

    Parece que estás intentando omitir líneas de código si la variable no se encuentra en la hoja. Para hacer esto, puedes usar una combinación de bucles For y declaraciones If. Por ejemplo:

    Dim a As Integer
    Dim b As Integer
    Dim D As Integer
    
    '{.......}
    
    ' a
    FreightStrMinimumList(1) = strFreightperMinCol:
    FreightStrMinimumList(2) = strFreightMinCol:
    FreightStrMinimum_List(3) = strMOtherMinCol
    
    ' b
    FreightColMinimumList(1) = FreightperMinCol:
    FreightColMinimumList(2) = FreightMinCol:
    FreightColMinimum_List(3) = MOtherMinCol
    
    ' d
    FreightStrPerKgList(1) = strFreightperKgCol:
    FreightStrPerKgList(2) = strFreightperkgAll_InCol:
    FreightStrPerKgList(3) = strFreightless45All_InCol:
    FreightStrPerKgList(4) = strFreightgreater45All_InCol:
    FreightStrPerKgList(5) = strFreight100All_InCol:
    
    ' esto continúa hasta (9)
    
    For a = 1 To 3
    For b = 1 To 3
    For D = 1 To 9
    
    If FreightStrMinimumList(a) = 0 Then GoTo nextsegment3
    If FreightColMinimumList(b) = 0 Then GoTo nextsegment3
    If FreightColPerKg_List(D) = 0 Then GoTo nextsegment3
    
    'líneas de código con cálculos con...end with
    
    nextsegment3:
    Next a
    Next b
    Next D
    

Comments are closed.