当用户在名为“ 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时,它起作用了。任何想法?预先感谢!