VBA kullanarak tatil listesindeki Tabloya göre tatili girin

Anonim

Soru:
Bir Çalışma Sayfasında ÇalışanAdı, HolidayStart ve HolidayEnd var. Sonraki ay sayfalarında her çalışanın tatillerini nasıl renklendirebilirim?

Cevap:
Aşağıdaki Kodu XL5/7 ile bir Modül Sayfasına, XL8 ile genel Modüle girin, bir Düğmeye atayın ve çalıştırın.

Aşağıdaki kodu standart modüle yerleştirin

Sub NewVacation() Dim rngFind As Aralık Dim intRow As IntRow, intMonth As Integer, intCounter As IntRow = 3 IsBoşa Kadar Yap(Cells(intRow, 1)) for intMonth = Month(Cells(intRow, 2)) To Month(Hücreler) (intRow, 3)) Set rngFind = Çalışma Sayfaları(Format(DateSerial(1, intMonth, 1), "mmmm")). _ Columns(1).Find _ (Cells(intRow, 1), LookIn:=xlValues, lookat:=xlWhole) if intMonth = Month(Cells(intRow, 2)) Ve intMonth = _ Month(Cells(intRow, 3) ) Sonra For intCounter = Day(Cells(intRow, 2)) To Day(Cells(intRow, 3)) rngFind.Offset(0, intCounter).Interior.ColorIndex = 3 Sonraki intCounter ElseIf intMonth = Ay(Cells(intRow, 2) )) Sonra For intCounter = Day(Cells(intRow, 2)) To Day(DateSerial _ (1, Month(Cells(intRow, 2)) + 1, 0))) rngFind.Offset(0, intCounter).Interior.ColorIndex = 3 Sonraki intCounter Else For intCounter = 1 To Day(Cells(intRow, 3)) rngFind.Offset(0, intCounter).Interior.ColorIndex = 3 Sonraki intCounter End If Sonraki intMonth intRow = intRow + 1 Döngü End Sub