Incrementación de número VBA en Excel

GromGrom Mensajes publicados 102 Estado Miembro -  
ThauTheme Mensajes publicados 1564 Estado Miembro -
Buenas noches a todos,

Estoy creando un formulario para registrar, modificar y consultar datos.
En el caso de registrar una nueva ficha, me gustaría que se incremente automáticamente un valor (1, 2, ...)
Aquí está mi fragmento de código que actualmente me obliga a introducir manualmente un valor en el ComboBox1.
¿Tienen alguna idea de solución?

Gracias por vuestra ayuda

Clem

Private Sub CommandButton1_Click()

Dim L As Integer

If MsgBox("Confirmez-vous l’insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d’ajout") = vbYes Then

L = Sheets("Clients").Range("a65536").End(xlUp).Row + 1

Range("A" & L).Value = ComboBox1
Range("B" & L).Value = ComboBox2
Range("C" & L).Value = TextBox1
Range("D" & L).Value = TextBox2
Range("E" & L).Value = TextBox3
Range("F" & L).Value = TextBox4
Range("G" & L).Value = TextBox5
Range("H" & L).Value = TextBox6
Range("I" & L).Value = TextBox7

End If

End Sub

1 respuesta

  1. ThauTheme Mensajes publicados 1564 Estado Miembro 160
     
    Hola GromGrom, hola el foro

    Reemplaza tu ComboBox1 por un textbox (TexBox8 normalmente).

    Si ya tienes un código de inicialización de tu UserForm, añade la línea:
    Me.TextBox8.Value = Application.WorksheetFunction.Max(Sheets("Clients").Columns(1)) + 1


    Si no, añade este código de inicialización:
    Private Sub UserForm_Initialize() Me.textbox8.Value = Application.WorksheetFunction.Max(Sheets("Clients").Columns(1)) + 1 End Sub


    Y adapta el código del CommandButton1 :
    Range("A" & L).Value = TetxBox8.Value


    --
    À plus,
    ThauTheme
    0