我有一个excel组合框创建为一个带有datavalidation的列表来显示状态。我在sheet3中保持相同的状态。当用户单击sheet1上的Validate按钮时,我需要比较sheet1和sheet3的状态,如果有更改,我必须显示一个警告,为更改添加Date。此外,我需要确保给定区域中的所有单元格都已填充,并且没有空白。这是我到目前为止所做的,但无法进行比较。
Sub Button2_Click()
Dim LastRow As Long
Dim NoOfCols As Long
Dim NoOfCells As Long
Dim StartRow As Integer
Dim EmpNo As Long
Dim NewStatus As String
Dim ActualStatus As String
Dim Wb As Workbook
Dim ws As Worksheet
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).row
End With
LastRow = LastRow - 8
NoOfCols = Range("A5:G" & LastRow).Columns.Count
NoOfCells = LastRow * NoOfCols
LastRow = LastRow + 4
If WorksheetFunction.CountA(Range("A5:G" & LastRow)) < NoOfCells Then
MsgBox "Please fill in all details"
Else
Set Wb = ThisWorkbook
Set ws = Wb.Sheets("Sheet3")
For StartRow = 5 To LastRow
EmpNo = Cells.Item(StartRow, 3)
NewStatus = Cells.Item(StartRow, 6)
With ws
Set FindRow = .Range("A:A").Find(What:=EmpNo, LookIn:=xlValues)
MsgBox FindRow
End With
Next StartRow
MsgBox "Data Successfully Validated"
End If
End Sub
End Sub