excel - 自动调用 Sub
问题描述
当用户在名为“Schema”的表内单击时,我想运行一个子程序。我正在尝试以下操作,但我在表格内单击,没有任何反应......
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'If not in the table, exit sub
If Intersect(Range("Schema"), ActiveCell.EntireRow) Is Nothing Then Exit Sub
Call MarkRow
End Sub
MarkRow 是这样的:
Sub MarkRow()
Dim cellno As String: cellno = Str(ActiveCell.row)
Dim myRowPos As Long
Dim myRow As Range
myRowPos = Selection.ListObject.Range.row
Set myRow = ActiveCell.EntireRow 'I want to select the row in the table ONLY
'Marking that row in yellow
Range("Schema").Interior.ColorIndex = 0
Application.ScreenUpdating = False
Range("B" & Trim(cellno) & ":I" & Trim(cellno)).Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(0, 255, 0)
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Application.ScreenUpdating = True
'Show above
If Not myRow Is Nothing And myRowPos >= 9 Then
Range("EditCountry").Value2 = ThisWorkbook.ActiveSheet.Range("B" & Trim(cellno)).Value2
Range("EditNodeName").Value2 = ThisWorkbook.ActiveSheet.Range("C" & Trim(cellno)).Value2
Range("EditNodeId").Value = ThisWorkbook.ActiveSheet.Range("D" & Trim(cellno)).Value2
Range("EditParentNode").Value = ThisWorkbook.ActiveSheet.Range("E" & Trim(cellno)).Value2
Range("EditParentNodeId").Value = ThisWorkbook.ActiveSheet.Range("F" & Trim(cellno)).Value2
Range("EditActive").Value = ThisWorkbook.ActiveSheet.Range("G" & Trim(cellno)).Value2
Range("EditFrom").Value = ThisWorkbook.ActiveSheet.Range("H" & Trim(cellno)).Value2
Range("EditTo").Value = ThisWorkbook.ActiveSheet.Range("I" & Trim(cellno)).Value2
End If
'Save row in the table with the modified data when clicking a button
End Sub
代码在同一个模块中......不明白为什么什么都不做。当我用按钮调用 MarkRow 时,它就可以工作了。任何想法?提前致谢!
解决方案
推荐阅读
- spring-boot - 如何为单个项目中运行的每个批次创建单独的日志文件?
- php - php变量[1]在实际编码中的含义
- jmeter - 如何在两个线程组之间使用变量
- jenkins - 在并行管道脚本 Jenkins 中运行作业
- c# - Time Series Insights 中的历史数据摄取和查询
- laravel - Laravel ide-helper 安装良好但不生成
- npm - 如何修复 NPM 漏洞(libcipm、libnpm、node-gyp、npm-lifecycle)?
- spring-boot - 使用 @EnableMongoAuditing 时找不到类型类的 PersistentEntity
- angular - Angular 7:多个字段,相同的表单控件名称
- java - 具有同名同级的 XML 解析