VBA to retrieve data from a row in a userform

isa38600 Posted messages 39 Status Member -  
cs_Le Pivert Posted messages 8437 Status Contributor -
Hello, I am looking to retrieve the data contained in the active cell’s row in a userform in order to modify it later... The code I found works but with a non-negligible bug: it correctly selects the row I want, but when the userform launches, the data from the row above has been retrieved... I haven’t found anything addressing my issue in various posts on the topic, I don’t understand why this happens and it’s starting to drive me crazy! I’m including my code below. Thanks in advance to kind souls who will explain what’s wrong!
Sub CommandButton2_Cliquer()

'select the row corresponding to the active cell
ActiveCell.EntireRow.Select

'split the elements "day", "month", "year" and place them into the corresponding comboboxes
Dim TabSep() As String
TabSep() = Split(Selection(ligne, 1).Value, " ")
UserForm2_modifier.ComboBox4.Value = TabSep(0)
UserForm2_modifier.ComboBox5.Value = TabSep(1)
UserForm2_modifier.ComboBox6.Value = TabSep(2)

'fill the form with the data from the selected row
UserForm2_modifier.ComboBox1.Value = Selection(ligne, 2)
UserForm2_modifier.ComboBox2.Value = Selection(ligne, 3)
UserForm2_modifier.ComboBox3.Value = Selection(ligne, 4)
UserForm2_modifier.TextBox1.Value = Selection(ligne, 5)
UserForm2_modifier.ComboBox7.Value = Selection(ligne, 6)
UserForm2_modifier.TextBox2.Value = Selection(ligne, 7)
UserForm2_modifier.ComboBox8.Value = Selection(ligne, 8)
UserForm2_modifier.ComboBox9.Value = Selection(ligne, 9)

'End With
'End If

'afficher le formulaire
UserForm2_modifier.Show

End Sub
Configuration: Windows / Edge 100.0.1185.44

1 answer

  1. cs_Le Pivert Posted messages 8437 Status Contributor 730
     
    Hello,

    the variable line is not declared!

    Dim ligne As Long ligne = ActiveCell.Row


    --
    @+ Le Pivert
    0