excel - 根据 Active-x Dropdown 自动填充一行中的单元格
问题描述
我有一个 Active-x 下拉菜单,并希望根据此下拉菜单自动填充行中的其他单元格。我在工作表更改事件中编写了代码,但是当我从此下拉列表中选择时,它不会触发其他行的自动填充代码。任何帮助,将不胜感激。 第 9 列是我的 active-x 下拉列表,但是当我从列表中选择时,在我的 Resource(sheet) 中显示下一个单元格的代码不会触发。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsSource As Worksheet
Dim r As Long
Set wsSource = ThisWorkbook.Sheets("Source") 'Source sheet
Application.EnableEvents = False
If Target.Column = 9 Then
r = Application.Match(Target.Value, wsSource.Columns(8), 0)
Target.Offset(0, 1) = wsSource.Cells(r, 9)
End If
Application.EnableEvents = True
End Sub
解决方案
更改 a 中的值Active X ComboBox
不会触发 a Worksheet_Change
。相反,使用ComboBox_Change
这样的事件:
Private Sub ComboBox1_Change()
MsgBox "Please share your code next time you post. It will greatly help others help you :)"
End Sub
您可能需要在运行代码之前验证所选值,这可以通过简单的If ComboBox1.Value = "?" Then
推荐阅读
- flutter - Gif 没有得到动画颤动网络
- c++ - 在 QtMultimedia 的 QAudioFormat 中为 24、32 和 64 位音频选择哪种样本类型(不是大小)?
- sql - SQL聚合查询重复主键列
- kotlin - 如何在 Kotlin 中创建不可变对象?
- gradle - Gradle 依赖管理强制版本
- c++ - 关于函数返回指针
- c# - 将列表接口转换为自定义列表类
- django-rest-framework - 如何仅在 DRF 中搜索所选字段?
- google-tag-manager - 有没有办法手动刷新 GTM 容器?
- mysql - 有没有一种方法可以让我加入两个表并在另一个表中显示