Visual Basic para Aplicaciones - error al recorrer rango con un bucle for

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

error al recorrer rango con un bucle for

Publicado por Xabier (2 intervenciones) el 09/07/2021 10:04:04
se queda siempre en el primer valor del rango, alguien sabe por qué puede ser?
Gracias de antemano

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Sub crearlista()
Dim Cosa As String
Dim Celda As Range
 
 
 
For Each Celda In Range("B2:I2")
    If Not IsEmpty(Celda.Value) Then
        Cosa = ActiveCell.Offset(-1, 0)
 
        With Worksheets("Hoja1").Range("L2").Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=Cosa
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    End If
Next Celda
 
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

error al recorrer rango con un bucle for

Publicado por JuanC (565 intervenciones) el 01/08/2021 13:44:58
probá cambiando ActiveCell por Celda
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Antoni Masana
Val: 1.134
Oro
Ha mantenido su posición en Visual Basic para Aplicaciones (en relación al último mes)
Gráfica de Visual Basic para Aplicaciones

error al recorrer rango con un bucle for

Publicado por Antoni Masana (498 intervenciones) el 03/08/2021 17:50:23
Cada vez que vas a añidir un nuevo valor borras el anterior

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Sub crearlista()
    Dim Celda As Range
 
    Worksheets("Hoja1").Range("L2").Validation.Delete
 
    For Each Celda In Range("B2:I2")
        If Not IsEmpty(Celda.Value) Then
            With Worksheets("Hoja1").Range("L2").Validation
                .Add Type:=xlValidateList, _
                     AlertStyle:=xlValidAlertStop, _
                     Operator:=xlBetween, _
                     Formula1:=ActiveCell.Offset(-1, 0)
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
        End If
    Next Celda
End Sub

Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar