Excel大神进。怎样实现操作鼠标点一下,是矩形选中区域,能理解的来

2025-02-25 16:04:54
推荐回答(1个)
回答1:

需要用VBA写代码。(样本文件见附件)

代码如下:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column <> 3 Then Exit Sub
If Target.Row < 6 Then Exit Sub
If Target = "" Then Exit Sub
mrow = Cells(Rows.Count, "c").End(3).Row
For i = mrow To 6 Step -1
    If Cells(i, "c") = Target.Value Then maxRow = i: Exit For
Next
minRow = Range("C:C").Find(Target, lookat:=xlWhole).Row
Cells.Interior.ColorIndex = 0
Dim rg As Range
Set rg = Cells(minRow, 1).Resize(maxRow - minRow + 1, 6)
rg.Interior.ColorIndex = 36
rg.Select
End Sub