Introduceți vacanța conform tabelului din lista de vacanță utilizând VBA

Cuprins

Întrebare:
Am EmployeeName, HolidayStart și HolidayEnd într-o foaie de lucru. Cum pot colora sărbătorile fiecărui angajat în fișele lunii următoare?

Răspuns:
Introduceți următorul cod cu XL5 / 7 într-o ModuleSheet, cu XL8 într-un modul general, atribuiți-l unui buton și executați-l.

Plasați codul de mai jos în modulul standard

Sub NewVacation () Dim rngGăsiți ca interval Dim intRow Ca întreg, intMonth As Integer, intCounter As Integer intRow = 3 Do Until IsEmpty (Cells (intRow, 1)) For intMonth = Month (Cells (intRow, 2)) To Month (Cells (intRow, 3)) Set rngFind = Foi de lucru (Format (DateSerial (1, intMonth, 1), "mmmm")). _ Coloane (1). Găsiți _ (Celule (intRow, 1), LookIn: = xlValues, lookat: = xlWhole) If intMonth = Month (Cells (intRow, 2)) And intMonth = _ Month (Cells (intRow, 3) ) Apoi Pentru intCounter = Ziua (Celule (intRow, 2)) To Day (Cells (intRow, 3)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Next intCounter ElseIf intMonth = Month (Cells (intRow, 2) )) Apoi pentru intCounter = Day (Cells (intRow, 2)) To Day (DateSerial _ (1, Month (Cells (intRow, 2)) + 1, 0)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Next intCounter Else For intCounter = 1 To Day (Cells (intRow, 3)) rngFind.Offset (0, intCounter) .Interior.ColorIndex = 3 Next intCounter End If Next intMonth intRow = intRow + 1 Loop End Sub

Vei ajuta la dezvoltarea site-ului, partajarea pagina cu prietenii

wave wave wave wave wave