Zadajte dovolenku podľa tabuľky v zozname prázdnin pomocou VBA

Obsah

Otázka:
Mám EmployeeName, HolidayStart a HolidayEnd v pracovnom hárku. Ako môžem vyfarbiť sviatky každého zamestnanca v listoch nasledujúcich mesiacov?

Odpoveď:
Zadajte nasledujúci kód s XL5/7 do ModuleSheet, s XL8 do všeobecného modulu, priraďte ho k tlačidlu a spustite ho.

Vložte kód nižšie do štandardné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"))). _ Stĺpce (1). Nájdite _ (bunky (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 Ďalší intCounter Iný pre intCounter = 1 do dňa (bunky (intRow, 3)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Ďalší koniec intCounter ak ďalší intMonth intRow = intRow + 1 koniec slučky Sub

Vám pomôže rozvoju miesta, zdieľať stránku s priateľmi

wave wave wave wave wave