|
本帖最后由 糊涂草 于 2024-2-27 15:32 编辑
第一个
'通用:判断哪些区域被选中会出现日期选择框
Private Const sCalenderRanges = "B5:B5|D5:D5|L3:L3"
'不同选区用“|”分隔
'一列或多列用:“B:B”、“D:H”
'一行或多行用:“A9:ZZ9”(第9行)、“A13:ZZ15”(第13-15行)
'长方形区域用:“F2:H6”
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iRng As Integer, sRng() As String, bInRng As Boolean
Dim i As Integer
'如果选区超过1个单元格,则不显示日期选择
If Target.Cells.Count > 1 Then
If IsFormLoaded("Calender") Then Calender.Hide
Exit Sub
End If
'如果日期选择已打开,先关闭
' If IsFormLoaded("Calender") Then Calender.Hide
'如果已有打开的用户窗体则隐藏
If UserForms.Count > 0 Then
For i = 0 To UserForms.Count - 1
UserForms(i).Hide
Next
End If
'如果不是选中的区域,则不显示日期选择
sRng() = Split(sCalenderRanges, "|")
bInRng = False
For iRng = 0 To UBound(sRng)
'检查 Target 在不在 设定的一个区域内
If Not Application.Intersect(Target, Range(sRng(iRng))) Is Nothing Then
bInRng = True
Exit For
End If
Next
If bInRng Then
Calender.Show (0)
End If
End Sub
第二个
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 2 Or Intersect(Target, Range("c2:c50000")) Is Nothing Then Exit Sub
UserForm1.Show
End Sub
下面这段能不能帮忙修改为指定的单元,2到3个,比如 G3 H8 K15
|
|