在文本框1中找到ID以查找未将复选框选择应用于该行的行



我无法获得以下代码来在列a中找到匹配的名称,然后将复选框选项应用于该行的挂起列。

代码


Private Sub CommandButton1_Click()
Dim lrEM As Long
Dim FoundID As Range
Set FoundID = Sheets("Employee-Software").Range("A:A").Find(What:=TextBox1.Text, Lookat:=xlWhole)
If Not FoundID Is Nothing Then
Sheets("Employee-Software").Cells(FoundID.Row, "A").Value = TextBox1.Text
Else
lrEM = Sheets("Employee-Software").Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets("Employee-Software").Cells(lrEM, "A").Value = TextBox1.Text
End If
If CheckBox1.Value = True Then
Sheets("Employee-Software").Cells(FoundID.Row, "B").Value = "Yes"
If CheckBox2.Value = True Then
Sheets("Employee-Software").Cells(FoundID.Row, "B").Value = "No"
End If
End Sub

由于缺少end if,您将无法按原样运行代码

如果您正在搜索A列中的文本框值,如果找到,为什么要将其作为文本框的值?

如果找不到文本框值,则不能使用FoundID.Row

是否仅在找到"是/否"值时才使用该值?

您不需要两个复选框,如果checkbox1=true,则"是",否则"否">

Private Sub CommandButton1_Click()
Dim lrEM As Long, x
Dim FoundID As Range, sh As Worksheet
Set sh = Sheets("Employee-Software")
With sh
x = IIf(CheckBox1 = True, "Yes", "No")
Set FoundID = .Range("A:A").Find(What:=TextBox1.Text, Lookat:=xlWhole)
If Not FoundID Is Nothing Then
'Sheets("Employee-Software").Cells(FoundID.Row, "A").Value = TextBox1.Text
FoundID.Offset(, 1) = x
Else
lrEM = .Range("A" & .Rows.Count).End(xlUp).Row + 1
.Cells(lrEM, "A").Value = TextBox1.Text
.Cells(lrEM, "B").Value = x
End If
End With
End Sub

我能找到的唯一问题是如果

If CheckBox1.Value = True Then
Sheets("Employee-Software").Cells(FoundID.Row, "B").Value = "Yes"
If CheckBox2.Value = True Then
Sheets("Employee-Software").Cells(FoundID.Row, "B").Value = "No"
End If

应该是

If CheckBox1.Value = True Then
Sheets("Employee-Software").Cells(FoundID.Row, "B").Value = "Yes"
else CheckBox2.Value = True Then
Sheets("Employee-Software").Cells(FoundID.Row, "B").Value = "No"
End If

最新更新