Sub Reset()
Dim iRow As Long
Dim ws As Worksheet
Dim cell As Range
Dim currentDate As Date
Dim targetDate As Date
Dim i As Long
iRow = [Counta(Semua!A:A)] ' identifying the last row
With frmForm
.txtNoFile.Value = ""
.txtTarikhNotis.Value = ""
.txtUlasan.Value = ""
.comboBoxStatus.Clear
.comboBoxStatus.AddItem "Selesai"
.comboBoxStatus.AddItem "Belum Selesai"
.lstSemuaData.ColumnCount = 5
.lstSemuaData.ColumnHeads = True
.lstSemuaData.ColumnWidths = "90,90,90,90,100"
' Clear the list box
.lstSemuaData.Clear
' Loop through the data and populate the list box
For Each cell In ws.Range("A2:E" & iRow)
' Calculate the target date (30 days ago)
targetDate = DateAdd("d", -30, currentDate)
' Check if the date in column 2 is past 30 days
If IsDate(cell.Cells(1, 2).Value) And cell.Cells(1, 2).Value <= targetDate Then
' If it's past 30 days, add the row with a different background color
.lstSemuaData.AddItem cell.Value
.lstSemuaData.List(i, 2) = cell.Cells(1, 2).Value ' Display the date
.lstSemuaData.List(i, 2, 1) = RGB(255, 0, 0) ' Highlight the date in red
Else
' If not, add the row without background color
.lstSemuaData.AddItem cell.Value
.lstSemuaData.List(i, 2) = cell.Cells(1, 2).Value ' Display the date
End If
i = i + 1
Next cell
End With
End Sub
我有Excel VBA代码的问题。所以,我想做的是从表Semua生成数据,并将其显示在列表框名称lstSemuaData上Semua表我有5列数据,第二列我有日期。如果日期超过第2列中日期后的30天,我想在列表框中突出显示该日期。
1条答案
按热度按时间sbdsn5lh1#
您可以使用
ListView
更改前景颜色和粗体。