excel - 通过设置条件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
用户表单:
解决方案
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.
推荐阅读
- python - 如何使用训练有素的 BERT 模型检查点进行预测?
- r - 尽管为 R3.5 安装文件提供了正确的源,Linux Mint 19 终端仍拒绝添加存储库
- android - 启用 TLS 1.2 的 Android Web 视图
- php - 在每个包含文件的开头添加 PHP 行
- html - 无法与表格一起添加水平滚动条
- angularjs - 根据angularJS中的内容动画元素的高度
- python - 如何根据用户输入生成随机数1和5,如果玩家猜对则打印正确如果错误则打印错误
- java - Hibernate 5.4.x 引起:org.hibernate.boot.MappingException:访问 stax 流时出错:origin(null)
- c# - C# Windows 服务使用 WinSCP 程序集不匹配作为对象引用未设置为对象的实例
- android - 捕获的图像显示模糊