目前我的电子表格看起来像这样
Name | Join date
AAAA | Jun 1, 2010
我想要做的是使用该数据向右侧添加具有接下来18个月的列:
Jan 2015 | Feb 2015 | Mar 2015 | etc
并且只有在未来18个月内有里程碑(10,20,30)时才会出现名称。
我还有这样做吗?我需要为它编写某种宏吗?或者是一套足够的公式吗?我希望它从表1中的列表中提取数据,然后将其输出到表2中。
我添加了一个示例屏幕截图:
https://i.imgur.com/HXCBXPm.png
不同的颜色是它们(10年,20年,30年)的里程碑
答案 0 :(得分:0)
很难准确理解为了写任何东西需要发生什么,但我可以为你提供一些想法来帮助你。你可以说,你必须连接点。
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
<强>链接:强> Color Palette