【发布时间】:2019-01-11 00:33:57
【问题描述】:
我有以下代码以绿色突出显示用户单击的行。 在代码的最后,我选择单元格 B6 以取消选择整行并将选择移到上方。 它工作正常,除了单元格 B6 也以绿色突出显示,我不希望这样。我怎样才能删除它?
在我的工作表中:
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 ClickInside
End Sub
在模块中:
Sub ClickInside()
Dim cellno As String: cellno = Str(ActiveCell.row)
Dim myRow As Range
Set myRow = ActiveCell.EntireRow 'I want to select the row in the table ONLY
Call Unprotect_table
Call MarkRow(cellno, myRow)
Call Protect_table
End Sub
Sub MarkRow(cellno As String, myRow As Range)
'Marking that row in green
Range("Schema").Interior.ColorIndex = 0
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 = False
'Show above
If Not myRow Is Nothing And CLng(cellno) >= 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
'Move selection
Range("B6").Select
End Sub
谢谢!
【问题讨论】:
-
你在哪里称呼潜艇? cellno 是全局变量吗?
-
感谢您访问@jivko。请查看已编辑的问题
-
如果您不想选择和更改 B6 - 为什么选择它?
-
@SolarMike 将选择移动到顶部。我想选择它但不想把它变成绿色。
-
那你为什么不检查一下Target呢?