Untitled

 avatar
unknown
plain_text
a year ago
2.4 kB
8
Indexable
Sub Gimtadienis()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long
    Dim birthDate As Date
    Dim today As Date
    Dim nextMonth As Date
    
    ' Set the worksheet to the active sheet
    Set ws = ActiveSheet
    
    ' Get today's date and the date 31 days from now
    today = Date
    nextMonth = DateAdd("d", 31, today)
    
    ' Find the last row with data in column B
    lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
    
    ' Loop through each cell in column B
    For i = 2 To lastRow ' Assuming the first row is headers
        ' Check if the cell is not empty and is a date
        If IsDate(ws.Cells(i, "B").Value) Then
            birthDate = ws.Cells(i, "B").Value
            
            ' Adjust the year of the birthDate to the current year
            birthDate = DateSerial(Year(today), Month(birthDate), Day(birthDate))
            
            ' If the birthday is within the next 31 days, highlight the row
            If birthDate >= today And birthDate <= nextMonth Then
                ws.Rows(i).Interior.Color = RGB(144, 238, 144) ' Light green color
            End If
        End If
    Next i
End Sub

Sub Pensija()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long
    Dim birthDate As Date
    Dim today As Date
    Dim nextMonth As Date
    
    ' Set the worksheet to the active sheet
    Set ws = ActiveSheet
    
    ' Get today's date and the date 31 days from now
    today = Date
    nextMonth = DateAdd("d", 31, today)
    
    ' Find the last row with data in column B
    lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
    
    ' Loop through each cell in column B
    For i = 2 To lastRow ' Assuming the first row is headers
        ' Check if the cell is not empty and is a date
        If IsDate(ws.Cells(i, "C").Value) Then
            birthDate = ws.Cells(i, "C").Value
            
            ' Adjust the year of the birthDate to the current year
            birthDate = DateSerial(Year(today), Month(birthDate), Day(birthDate))
            
            ' If the birthday is within the next 31 days, highlight the row
            If birthDate >= today And birthDate <= nextMonth Then
                ws.Rows(i).Interior.Color = RGB(255, 0, 0) ' Light green color
            End If
        End If
    Next i
End Sub
Editor is loading...
Leave a Comment