各位电商运营的小伙伴,在参加各种活动的时候,常常活动时间有重叠,然后重叠期提报的商品却不能是重复的,这个时候,我总希望如果各个活动的跨期,可以用颜色块标示出来就会显得比较清晰,在网路上搜了一下相关的日程管理或者项目管理的工具,功能都比较复杂,也比较好用,但是却没有满足我的简单需求,正好最近在学习VBA,所以想自己试着写一个类似的工具。
最后做出来的样子是这样的。
操作面板.png
输入必要的信息,点击添加日程后,就可以清晰的展现各个活动的时间跨度了。
示例.png设计的思路如下:
image.png
这边的非法验证就没有去写了,默认用户输入的都是合法的数据。
源代码如下:
首先是展示日程,并且添加色块的load函数:
Option Explicit
Public Function load(pro_name As String, start_date_name As String, end_date_name As String)
Dim pro_n As String
Dim start_date As Variant
Dim end_date As Variant
Dim first_date As Variant
Dim rng_last As Range
Dim rng_last_row As Long
Dim first_to_end As Variant
Dim first_to_start As Variant
Dim start_cells As Range
Dim end_cells As Range
Dim rng_last_date As Range
Let pro_n = pro_name
Let start_date = CDbl(CDate((start_date_name)))
Let end_date = CDbl(CDate((end_date_name)))
Let first_date = CDbl(CDate(("2019/1/1")))
Let first_to_end = end_date - first_date
Let first_to_start = start_date - first_date
Set rng_last = Sheet1.Range("A65536").End(xlUp).Offset(1, 0)
Let rng_last_row = rng_last.Row
Set start_cells = Sheet1.Cells(rng_last_row, 2).Offset(0, first_to_start)
Set end_cells = Sheet1.Cells(rng_last_row, 2).Offset(0, first_to_end)
Let rng_last = pro_n
Sheet1.Range(start_cells, end_cells).Interior.ColorIndex = Int((50 - 20 + 1) * Rnd + 20)
End Function
然后是几个按钮的cliick事件
Option Explicit
Private Sub btn_date_Click()
Dim pro_name As String
Dim start_date As String
Dim end_date As String
pro_name = date_tbx.Text
start_date = "2019/" & start_tbx.Text
end_date = "2019/" & end_tbx.Text
Call load(pro_name, start_date, end_date)
End Sub
Private Sub btn_look_Click()
Sheet1.Activate
End Sub
如果大家有任何建议,或者希望可以看看源文件的,我可以把文件发给大家。
大家可以留下邮箱。
网友评论