excel - 多次调用函数
问题描述
我的代码有问题。
在工作表“主要”中,我有以下代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Application.EnableEvents = False
Application.Calculation = xlManual
Application.ScreenUpdating = False
ThisWorksheet.EnableCalculation = False
Set Target = Tabelle1.Range("D6")
If Not Intersect(ActiveCell, Target) Is Nothing Then
Dim OpenFiles As String
wbcount = Application.Workbooks.count
For i = 1 To wbcount
If OpenFiles = "" Then
OpenFiles = Application.Workbooks(i).Name
Else
OpenFiles = OpenFiles & "," & Application.Workbooks(i).Name
End If
Next
With Target.Validation
.Delete
.Add Type:=xlValidateList, Formula1:=OpenFiles
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
End Sub
这使得从下拉列表中选择打开的工作簿成为可能。我使用了一些不同的函数,这些函数在“主”表中的选定单元格中调用。我的问题是,我在这些函数中有一些输入框:这些都被调用了两次,我怎样才能避免这个问题?
示例函数的代码:
功能之一的代码:
Public Function getSerialStr(hcc1 As String)
Dim wb As Workbook
Set wb = Workbooks(hcc1)
Dim i As Integer, j As Integer, count As Integer
Dim hcc As Worksheet
For i = 1 To wb.Worksheets("Table 1").UsedRange.Rows.count
For j = 1 To 15
If InStr(1, wb.Worksheets("Table 1").Cells(i, j).Value2, "Serial", 1) > 0 Then
itis = wb.Worksheets("Table 1").Cells(i + 1, j).Value
If Len(itis) < 4 Then
itis = InputBox("No Serial found, please type in manually!", "Serial Missing" & vbCrLf)
GoTo ende
End If
GoTo ende
End If
Next j
Next i
ende:
getSerialStr = itis
End Function
解决方案
推荐阅读
- python - 在 GPU 上强制执行 python 脚本
- sql - 在 SQL 中,在 where 语句中返回值时,“IS”和“=”有区别吗?
- docker - Webpack-Dev-Server 构造了不正确的 SockJS:“可能无法从通过 HTTPS 加载的页面启动不安全的 SockJS 连接”
- node.js - 将 csv 转换为 JSON,并在文档顶部添加注释 (Node.js)
- excel - 使用命名范围使用 vba 创建 excel 数据验证
- java - 将两个 ArrayList 并行合并为一个 ArrayList?
- android - 将选中的单选按钮的值作为字符串并将其存储在 Firebase
- c# - 使用 Asp.NET Core 3.1 框架将文件上传到服务器时如何使用 IFormFile 作为属性?
- vb.net - 获取所有 Outlook 电子邮件(包括服务器上的电子邮件)
- ruby-on-rails - 如何创建(我认为)需要 PostgreSQL 子查询的 Rails 查询?