VBA将突出显示识别多个单元格
我有以下VBA脚本:VBA将突出显示识别多个单元格,vba,excel,Vba,Excel,我有以下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.ScreenUpda
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”中返回整个星期的范围。见:
然后在单元格“SelecedCell1”中返回2017年8月1日至2017年8月5日(整个范围)
不确定如何调整此VBA脚本。我们将不胜感激。谢谢。[selectedCell1]。调整大小(Target.Rows.Count,Target.Columns.Count)=Target.Value
不使用ActiveCell:)
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