Otázka:
Mám EmployeeName, HolidayStart a HolidayEnd v listu. Jak mohu vybarvit svátky každého zaměstnance v následujících měsíčních listech?
Odpovědět:
Zadejte následující kód s XL5/7 v modulu ModuleSheet, s XL8 v obecném modulu, přiřaďte jej k tlačítku a spusťte jej.
Umístěte níže uvedený kód do standardního modulu
Sub NewVacation () Dim rngFind As Range Dim intRow As Integer, intMonth As Integer, intCounter As Integer intRow = 3 Do Before IsEmpty (Cells (intRow, 1)) For intMonth = Month (Cells (intRow, 2)) to Month (Cells (intRow, 3)) Set rngFind = Worksheets (Format (DateSerial (1, intMonth, 1), "mmmm")). _ Sloupce (1). Najděte _ (buňky (intRow, 1), LookIn: = xlValues, lookat: = xlWhole) If intMonth = Month (Cells (intRow, 2)) And intMonth = _ Month (Cells (intRow, 3) ) Then For intCounter = Day (Cells (intRow, 2)) To Day (Cells (intRow, 3)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Next intCounter ElseIf intMonth = Month (Cells (intRow, 2 )) Then For intCounter = Day (Cells (intRow, 2)) To Day (DateSerial _ (1, Month (Cells (intRow, 2)) + 1, 0)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Další intCounter Jinak pro intCounter = 1 do dne (buňky (intRow, 3)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Další intCounter End If Next intMonth intRow = intRow + 1 Loop End Sub