Excel 基于连接日期对数据进行排序和筛选
目前我有一个类似这样的电子表格Excel 基于连接日期对数据进行排序和筛选,excel,vba,Excel,Vba,目前我有一个类似这样的电子表格 Name | Join date AAAA | Jun 1, 2010 我想做的是使用这些数据在右边添加列,这些列包含接下来的18个月,如下所示: Jan 2015 | Feb 2015 | Mar 2015 | etc 只有在未来18个月内有10、20、30个里程碑时,这些名字才会出现 我有什么理由这样做吗?我需要为它编写某种宏吗?还是一套公式就足够了?我希望它从表1中的列表中提取数据,并将其输出到表2中 我添加了一个示例屏幕截图: 不同的颜色代表了10年、
Name | Join date
AAAA | Jun 1, 2010
我想做的是使用这些数据在右边添加列,这些列包含接下来的18个月,如下所示:
Jan 2015 | Feb 2015 | Mar 2015 | etc
只有在未来18个月内有10、20、30个里程碑时,这些名字才会出现
我有什么理由这样做吗?我需要为它编写某种宏吗?还是一套公式就足够了?我希望它从表1中的列表中提取数据,并将其输出到表2中
我添加了一个示例屏幕截图:
不同的颜色代表了10年、20年、30年的里程碑。很难确切地理解写任何东西需要发生什么,但我可以为您提供一些想法,帮助您度过难关。可以说,你必须把这些点连起来
Sub LoopFormatting()
Dim lastRow As Long
Dim sheet As String
Dim joinDate As Date
Dim gap As Long
sheet = "Sheet1"
lastRow = Sheets(sheet).Range("A" & Rows.Count).End(xlUp).row
'Loop through Sheet1.
For lRow = 2 To lastRow
'get the join date and name it as a variable
joinDate = Sheets(sheet).Cells(lRow, "B") ' Where is the joinDate
'Loop through columns from n To n + 18
For lCol = n to n +18 'set n as the column number that your months start
'set gap variable here based on month(JoinDate) and month(column Month Date)
gap = Month(joinDate) - Month(columnDate) 'You will know these variable names
'Evaluate with Select Case gap and Set the Value for the cell with the .interior.colorindex property
Select Case gap
Case Is = 120
Sheets("Sheet2").Cells(lRow, lCol) = dateValue 'The date you are entering in the column
Sheets("Sheet2").Cells(lRow, lCol).Interior.colorindex = 3 'Set whatever you want here.
Case Is = 240
'insert your choices for formatting and values to be set
Case Is = 360
'insert your choices for formatting and values to be set
End Select
Next lCol
Next lRow
End Sub
链接:
我刚刚添加了一个例子,说明最后一个应该是什么样子的。这些是我用手手动完成的。对不起,你能澄清一下你说不出来是什么意思吗?