在Excel日历中创建动态链接
我有一个宏,它根据当月的当前日期创建日历,并输出典型的日历格式在Excel日历中创建动态链接,excel,vba,dynamic,Excel,Vba,Dynamic,我有一个宏,它根据当月的当前日期创建日历,并输出典型的日历格式 Sub Calendar() Dim cDater, endDater, tempDater As Date Dim wDay As Variant Dim i, ColNum, dInMonth, cDayNum, dRange, rNum As Integer cDater = Date 'NORMAL 'cDater = DateValue("11/24/2019") 'TESTIN
Sub Calendar()
Dim cDater, endDater, tempDater As Date
Dim wDay As Variant
Dim i, ColNum, dInMonth, cDayNum, dRange, rNum As Integer
cDater = Date 'NORMAL
'cDater = DateValue("11/24/2019") 'TESTING
dRange = 30
dInMonth = Day(DateSerial(Year(cDater), Month(cDater) + 1, 1) - 1)
endDater = cDater + (dRange - 1)
rNum = 4
With Sheets("Calendar")
.Range("B4:H9").Clear
.Range("B4:H9").HorizontalAlignment = xlLeft
.Range("B4:H9").VerticalAlignment = xlTop
For i = 0 To (dRange - 1) 'NORMAL
'For i = 0 To 3 'TESTING
tempDater = cDater + i
cDayNum = Day(tempDater)
ColNum = (Weekday(tempDater, vbSunday) Mod 8) + 1
.Cells(rNum, ColNum).Select
.Cells(rNum, ColNum).Value = cDayNum
.Cells(rNum, ColNum).NumberFormat = "mm/dd"
If ColNum = 8 Then rNum = rNum + 1
Next
End With
End Sub
日历生成后,是否有方法从每个单元格创建动态链接以获取这些特定日期的信息
例如,如果我单击单元格,我希望Excel自动生成当天发生的事情的列表。如果Y个人一天中有X个事件,我希望输出如下:
主要群组:10个
人A:2
B人:3人
C:5人
在某种程度上,我认为它可能类似于透视表,但我不确定如何使用动态链接和/或VBA来设置所有这些。Update:我尝试使用以下代码作为测试工具启动,但Excel不允许我逐步完成。如下所示:
Sub tester(ByVal targCel作为范围)Dim dateSel作为变量表(“日历”)。Activate dateSel=ActiveCell.Value If Selection.Count>1然后退出Sub如果不相交(目标,范围(“B4:H8”))为空,然后运行“Dash_Builder”End If End If End If End If End If End子功能Dash_Builder(dateSel作为变体)MsgBox“它的功能”结束函数
关于为什么会发生这种情况有什么想法吗?谢谢!还有-显然,返回字符在注释中对我来说不起作用。失败。从头开始。我自己解决了这个问题。我必须切换选项,将SelectionChange功能包括在整个工作簿excel中,而不仅仅是general/normal。