gpt4 book ai didi

vba - Worksheet_BeforeDoubleClick 进行选择

转载 作者:行者123 更新时间:2023-12-04 22:03:03 26 4
gpt4 key购买 nike

我有以下代码不适用于选择:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Rng1 As Range
Dim I As Integer

If Selection.Count > 1 Then

For Each cell In Selection
If I = 0 Then
Set Rng1 = Range(cell.Address)
Else
Set Rng1 = Union(Range(cell.Address), Rng1)
End If
I = I + 1
Next cell
MsgBox "You have selected the range " & Rng1.Address(False, False)
Rng1.End(xlDown).Offset(0, 1).Activate
Else
MsgBox "you are in " & ActiveCell.Address(False, False)
ActiveCell.Offset(1, 0).Activate
End If


End Sub

我尝试选择一系列单元格然后双击,有人知道这是否可能吗?

最佳答案

因为双击会折叠您之前所做的任何多单元格选择,所以您需要跟踪它,然后检查是否 Target在里面。

就像是:

Dim rng As Range

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not rng Is Nothing Then
If Not Application.Intersect(Target, rng) Is Nothing Then
Debug.Print "Clicked in selected range: " & rng.Address()
Else
Debug.Print "Cell: " & Target.Address()
End If
Set rng = Nothing
Else
Debug.Print "No previous range: clicked in " & Target.Address()
End If
End Sub

'keeping track of the last multi-cell range selected....
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Set rng = Target
End Sub

关于vba - Worksheet_BeforeDoubleClick 进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com