excel - 如何使用 VBA 在多个工作表中修改选定 Excel 工作表中的记录
问题描述
我有一个 Excel 数据输入表单和两个 Excel 数据库表,分别是 Table1 和 Table2。在数据输入表单中,我提供了一个选择 Table1 或 Table2 的选项,并且我想使用数据输入表单中的修改按钮根据我的表选择来修改 Table1 记录或 Table2 记录。表记录应根据序号进行修改。但是当我选择一个表并使用序列号修改所选表中的记录时,错误显示为“未找到记录”。这是为什么?如何解决这个问题?下面给出了用于修改记录的 module1 编码
Sub ModifyRecord()
Dim iRow As Long
Dim iSerial As Long
iSerial = Application.InputBox("Please enter Serial Number to make modification.", "Modify", , , , , , 1)
On Error Resume Next
iRow = Application.WorksheetFunction.IfError _
(Application.WorksheetFunction.Match(iSerial, Sheets("Database").Range("A:A"), 0), 0)
On Error GoTo 0
If iRow = 0 Then
MsgBox "No record found.", vbOKOnly + vbCritical, "No Record"
Exit Sub
End If
Sheets("Form").Range("L1").Value = iRow
Sheets("Form").Range("M1").Value = iSerial
Sheets("Form").Range("H9").Value = Sheets("Database").Cells(iRow, 2).Value
Sheets("Form").Range("H11").Value = Sheets("Database").Cells(iRow, 3).Value
Sheets("Form").Range("H13").Value = Sheets("Database").Cells(iRow, 4).Value
Sheets("Form").Range("H15").Value = Sheets("Database").Cells(iRow, 5).Value
Sheets("Form").Range("H17").Value = Sheets("Database").Cells(iRow, 6).Value
Sheets("Form").Range("H19").Value = Sheets("Database").Cells(iRow, 7).Value
Sheets("Form").Range("H21").Value = Sheets("Database").Cells(iRow, 8).Value
Sheets("Form").Range("H23").Value = Sheets("Database").Cells(iRow, 9).Value
End Sub
sheet1(form) coding for modifying a record is given below
Private Sub cmdModify_Click()
Dim msgValue As VbMsgBoxResult
msgValue = MsgBox("Do you want to modify the record?", vbYesNo + vbQuestion, "Modify Record")
If msgValue = vbYes Then
Call ModifyRecord
End If
End Sub
如何修复此错误。请帮我
解决方案
推荐阅读
- c# - 如何使用新的 Azure.Storage.Blobs 命名空间仅获取 blob 中的文件夹名称
- sql - SQL 中两个 SELECT 语句的减法(redshift)
- powershell - Invoke-RestMethod PowerShell Google DDNS
- django - 使用 apache2 部署 django 项目时出现 404 错误
- python - Keras 中的 CPU 与 GPU 使用情况(Tensorflow 2.1)
- spring - Spring Application.Properties 和 Application-dev.properties 文件参数冲突
- reactjs - 使用 React Hooks 限制 Firebase 重新渲染
- reactjs - 在用户编辑时重置网格数据
- c# - 将二进制字符串转换为int c#
- python - 为什么插入排序的这段代码不起作用?