Добавление элементов путем установки условия VBA - PullRequest
0 голосов
/ 06 августа 2020

У меня есть список ниже: enter image description here

I want to add items in columns C, E, G, I ... till the last column. The idea is to look for the numbers on the first row in columns C, E, G ..., we select that number from a combobox (Combobox_Num) we look for it in the row 1 when we find it we add the data on the right column. For example if a choose 001 from my combobox, the data should be added on the last row of column C, then I have to add the date aswell on the next column (column D for this example). I've written this piece of code but it's do nothing, where is my mistake ? Thank you

Private Sub CommandButton1_Click()
If Me.ComboBox_Lame.Value = "" Then
    MsgBox ("Veuillez choisir une lame")
Else
'Nom_Lame = Me.ComboBox_Lame.Value
Num_Lame = Me.ComboBox_Num.Value

Dim ws_verifM1 As Worksheet
Set ws_verifM1 = ActiveWorkbook.Worksheets("Verif_M1")
fin_liste = ws_verifM1.Range("A" & Rows.Count).End(xlUp).Row
'fin_col = ws_verifM1.Cells(1, Columns.Count).End(xlToLeft).Column

Dim Plage As Range
Set Plage = ws_verifM1.Rows(1)

Set Trouve = Plage.Cells.Find(what:=Num_Lame)
If Trouve Is Nothing Then
Else
    ws_verifM1.Cells(1, Trouve.Column).Value = Num_Lame
    
    ws_verifM1.Cells(Trouve.Rows, 3) = Me.ComboBox_Lame.Value & Me.ComboBox_Operation.Value
    ws_verifM1.Cells(Trouve.Rows, 4) = Me.TextBox_Date.Value
End If
End If
Unload Me
End Sub

the userform :

введите описание изображения здесь

1 Ответ

0 голосов
/ 09 августа 2020

Поскольку я не могу express предложенный мной код четко указать в поле для комментариев (он не отображает возврат каретки), я просто напишу его здесь:

ws_verifM1.Cells(fin_liste + 1, 3) = Me.ComboBox_Lame.Value & Me.ComboBox_Operation.Value 

ws_verifM1.Cells(fin_liste + 1, 4) = Me.TextBox_Date.Value

Пожалуйста, скажите, понял ли я ваше намерение.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...