首页 > 解决方案 > 通过设置条件VBA添加项目

问题描述

我有以下清单: 在此处输入图像描述

我想在 C、E、G、I 列中添加项目...直到最后一列。我们的想法是在 C、E、G 列的第一行中查找数字...,我们从组合框 (Combobox_Num) 中选择该数字,当我们找到它时,我们在第 1 行中查找它我们添加数据右栏。例如,如果从我的组合框中选择 001,则应将数据添加到 C 列的最后一行,然后我必须在下一列(本示例的 D 列)中添加日期。我已经写了这段代码,但它什么也没做,我的错误在哪里?谢谢

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

用户表单:

在此处输入图像描述

标签: excelvba

解决方案


Since I cannot express my suggested code clearly in comment box (it does not display carriage return), I will just type it here:

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

Please tell if I have understood your intention.


推荐阅读