【发布时间】:2015-03-14 18:19:10
【问题描述】:
我正在尝试在 Excel 的宏中创建一个数组数组。这是我的问题...我正在创建一个年历,并希望突出显示该日历中的日期。
我在工作表中有一个日期范围。这些可以是我想记住的任何类型的日期,等等。我将它们读入,然后创建日历并将这些不同的日期设置为不同的背景颜色。
9/24/2015
1/20/2015
4/5/2015
9/30/2015
1/1/2015
在我有限的想法中,我会将它们读入,按月分组(年份无关紧要),然后输入与该月相关的日期。
9 -> 24, 30
1 -> 20, 1
4 -> 5
这是我目前所拥有的
'Set Variables
Dim ImportantDays As Variant
Dim id As Integer
Dim tempSplitDateArray() As Integer
'Grab the dates from the entered WorkSheet
ImportantDays = Worksheets("MainData").Range("E4:E19")
'Loop through the dates entered
For id = LBound(ImportantDays, 1) To UBound(ImportantDays, 1)
If ImportantDays(id, 1) <> "" Then
tempSplitDateArray() = Split(ImportantDays(id, 1), "/")
'--I now have tempSplitDateArray(0) = month
'--tempSplitDateArray(1) = day
'------------------------------------
'-- Not sure of my next step here
'------------------------------------
End If
Next id
我知道我可以有一个 2D 阵列,但我如何跟踪打开的阵列槽?我有这个变量(12 是月份,16 是允许的日期总数)。
Dim monthlyDates(12, 16) As Variant
理想情况下,我会将所有 9 月份的月份存储在monthlyDates(9) 或类似的东西中,但我不知道......
- 存储时如何跟踪?
- 在创建特定月份时如何访问和循环访问这些值?
有什么想法吗?
【问题讨论】:
-
我不明白您需要什么二维数组或数组数组。日期是一个奇异值,您只需要一个包含日历日的数组和一个包含重要日子的数组。我在这里错过了什么?
-
我试图有一个简单的数组来保存特定月份的所有日期。这意味着我需要一个与一个值相关联的天数组,让我知道哪个月。