我无法获得以下代码来在 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 然后"is",否则“否”
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
关于excel - 在文本框 1 中找到 ID 以查找未将复选框选择应用于该行的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53467555/