我有以下VBA脚本:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
If Not Application.Intersect(Target, Range("calendar")) Is Nothing Then
[selectedCell1] = ActiveCell.Value
Application.ScreenUpdating = True
End If
End Sub
目前,它识别只突出显示一个单元格并将其返回到名为selectedCell1的特定单元格中。
如果我选择包含日期“03/08/2017”的单元格N25,则会将“03/08/2017”返回到名为“selectedCell1”的另一个单元格单元格中。
但我想要它做的是,意识到我选择了整个星期,然后在单元格“selectedCell1”中返回整个星期范围。看到:
然后返回01/08/2017 - 05/08/2017(整个范围)单元格“selecetedCell1”。
不确定如何调整此VBA脚本。帮助将不胜感激。感谢。
答案 0 :(得分:1)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
If Not Application.Intersect(Target, Range("calendar")) Is Nothing Then
If Target.Cells.Count = 1 Then
[selectedCell1] = Target.Value
Else
[selectedCell1] = Format(Application.WorksheetFunction.Min(Target), "dd/mm/yyyy") & " - " & Format(Application.WorksheetFunction.Max(Target), "dd/mm/yyyy")
End If
Application.ScreenUpdating = True
End Sub