Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何使用数据输入表单编辑行?_Excel_Vba - Fatal编程技术网

Excel 如何使用数据输入表单编辑行?

Excel 如何使用数据输入表单编辑行?,excel,vba,Excel,Vba,我有一份数据输入表和数据表,如表1和表2所示 在数据输入表单中,首先我可以选择数据表。然后我在项目框中键入一个项目,并将数据保存到该数据表中 当我为现有项目输入数据时,它会生成另一行,该项目会转到新行,因此它会创建重复项 我需要更新数据表中的现有行 Sub Save_Details() 将表格设置为工作表 将表单设置为工作表 Dim iCurrentRow为整数 作为字符串的Dim sTableName Set shForm=ThisWorkbook.Sheets(“表单”) sTableNam

我有一份数据输入表和数据表,如表1和表2所示

在数据输入表单中,首先我可以选择数据表。然后我在项目框中键入一个项目,并将数据保存到该数据表中

当我为现有项目输入数据时,它会生成另一行,该项目会转到新行,因此它会创建重复项

我需要更新数据表中的现有行

Sub Save_Details()
将表格设置为工作表
将表单设置为工作表
Dim iCurrentRow为整数
作为字符串的Dim sTableName
Set shForm=ThisWorkbook.Sheets(“表单”)
sTableName=shForm.Range(“H7”)值
Set shTable=ThisWorkbook.Sheets(sTableName)
iCurrentRow=shTable.Range(“A”&Application.Rows.Count).End(xlUp).Row+1
用shTable
.Cells(iCurrentRow,1)=iCurrentRow-1
.Cells(iCurrentRow,2)=shForm.Range(“H9”)
.Cells(iCurrentRow,3)=shForm.Range(“H11”)
.Cells(iCurrentRow,4)=shForm.Range(“H13”)
.Cells(iCurrentRow,5)=shForm.Range(“H15”)
.Cells(iCurrentRow,6)=shForm.Range(“H17”)
.Cells(iCurrentRow,7)=shForm.Range(“H19”)
.Cells(iCurrentRow,8)=shForm.Range(“H21”)
.Cells(iCurrentRow,9)=shForm.Range(“H23”)
.Cells(iCurrentRow,10)=Application.UserName
.Cells(iCurrentRow,11)=格式([Now()],“DD-MMM-YYYY HH:MM:SS”)
以
shForm.Range(“H7、H9、H11、H13、H15、H17、H19、H21、H23”)。Value=“”
MsgBox“数据已成功保存!”
端接头
只需更换您的线路即可

iCurrentRow = shTable.Range("A" & Application.Rows.Count).End(xlUp).Row + 1
总是在shTable中找到第一个空行

Dim vMatched As Variant
iCurrentRow = shTable.Range("A" & Application.Rows.Count).End(xlUp).Row
vMatched = Application.Match(shForm.Range("H9").Value2, shTable.Range("B1:B" & iCurrentRow), 0)
If IsError(vMatched) Then
    iCurrentRow = iCurrentRow + 1
Else
    iCurrentRow = vMatched
End If

它将尝试从
shForm.Range(“H9”)
中找到值(是您的项目名称吗?)。如果找到,请更换现有的,否则请添加一个新的

得到答案,先生。非常感谢你,先生。上帝保佑你。@sadupa-作为新用户,请允许我说一句话:如果你觉得答案有帮助,那么将其标记为“已接受”对其他读者也是很有帮助的(接受由答案旁边的彩色复选标记表示)。到岸价。