我正在尝试从主列表中删除一堆标签,但是确认部分出现问题。我设法使整个删除过程都能正常工作,但是在尝试确认标签实际上已删除时遇到了麻烦。
我有2个文本框,其中一个用户在其中输入输入内容,另一个显示结果。我希望第二个显示“项目已删除”或“找不到项目”。
我似乎不知道该怎么办。
这是我的代码:
Private Sub BtnSubmit_Click()
TxtResult.Value = ""
Multi_FindReplace
End Sub
Public Sub Multi_FindReplace()
Number() = Split(TxtNumbers.Text, vbNewLine)
'Loops to find the asset tags through the list
For x = LBound(Number()) To UBound(Number())
'Confirms the Asset Tag is 7 characters
If Len(Number(x)) = 7 Then
For Each sht In ActiveWorkbook.Worksheets
'Deletes the actual Asset Tag from the list
sht.Cells.Replace What:=Number(x), Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
Next
Else
TxtResult.Value = TxtResult.Value & vbNewLine & "Invalid C#"
End If
Next
End Sub
Public Sub Results()
If TxtResult.Value = "" Then
TxtResult.Value = Number(x) & " Was Removed!"
Else
TxtResult.Value = TxtResult.Value & vbNewLine & Number(x) & " Was Removed! "
End If
End Sub
谢谢!
答案 0 :(得分:0)
您应该公开将x声明为整数,并将number()数组声明在模块顶部。从ActiveWorkbook的所有工作表中成功删除资产标签后,请调用结果子。
我还没有测试代码,但是看起来应该像这样:
Public x as Integer
Public Number()
[...]
If Len(Number(x)) = 7 Then
For Each sht In ActiveWorkbook.Worksheets
'Deletes the actual Asset Tag from the list
sht.Cells.Replace What:=Number(x), Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
Next
Results
Else
有关详细信息,请参见“调用子程序和功能过程”帮助文件。