我对 VBA 还不太熟悉,所以很难解决这个问题……我有一个用户窗体,其中包含各种输入,包括一些使用 Excel 工作表列表的组合框。我想要做的是,如果用户向该组合框添加了一个新值,则在保存表单时,它应该检查列表,如果该值不存在,则将其添加到列表末尾。这是我目前为止尝试根据在线找到的内容整理出来的(一旦我成功完成,我将把它放入循环中以覆盖多个组合框):
Dim ws As Worksheet: Set ws = Sheets("Lists")
Dim EmptyRow As Long
Dim FoundVal As Range
EmptyRow = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row + 1
If CoBJobList1.ListIndex > -1 Then
Set FoundVal = ws.Range("D2:D" & EmptyRow).Find(CoBJobList1.Value)
If Not FoundVal Is Nothing Then
'Do Nothing
Else
ws.Range("D" & EmptyRow).Value = CoBJobList1.Value
End If
End If