我有一个团体全年的时间表。第三行有一年的所有日期,下几行有每个组成员的名称。
A4:A9中规定的成员。假日在单元格A20:A28中指定。
所以,我想要做的是,可能通过VBA,制定一个类似于条件格式的规则,在B4:B9中插入单词"Holiday“,如果B3匹配日期为20澳元:28美元,然后插入C4:C9 (如果C3匹配等等)。
现在我不能在每个单元格中写入这个条件,因为它是每个成员使用的时间表,这是我在googling中经常得到的建议,而且我不能使用条件格式,所以我猜VBA是可行的方法,但是到目前为止我发现的VBA代码似乎使用了特定的单元格,并且不会遍历每一列。
发布于 2016-11-25 14:09:23
无需质疑您的一般方法,执行您计划做的工作的简单代码可以如下所示:
Option Explicit
Sub markhd()
' get calendardays, holidays and employees somehow into collections
' that can be looped. Since that information is stored in a worksheet,
' using ranges is one way to achive that
' holidays
Dim rhd As Range
Set rhd = ActiveSheet.Range("A20:A28")
' group employees
Dim remp As Range
Set remp = ActiveSheet.Range("A4:A9")
' calendar days
Dim rcal As Range
Set rcal = ActiveSheet.Range("B3:NB3")
Dim c As Object
' Loop every day (every c-object in your calendar days),
' then write "Holiday", if it matches an entry in your holiday-range
For Each c In rcal
If Not IsError(Application.Match(c, rhd.Cells, False)) Then
remp.Offset(0, c.Column - remp.Column).Value = "Holiday"
End If
Next c
End Sub注意:
希望这能帮上忙!
https://stackoverflow.com/questions/40806003
复制相似问题