Vba 修改现有数据输入excel电子表格以将数据保存到其他xls
我想要的只是最简单的excel数据输入表单。我已经制作了一个非常可用的免费xls表单数据输入表的稍微修改版本,我想对其进行修改,以便它将用户输入的数据导出到另一个电子表格,当前将导出到另一个工作表 这是我到目前为止的代码Vba 修改现有数据输入excel电子表格以将数据保存到其他xls,vba,excel,Vba,Excel,我想要的只是最简单的excel数据输入表单。我已经制作了一个非常可用的免费xls表单数据输入表的稍微修改版本,我想对其进行修改,以便它将用户输入的数据导出到另一个电子表格,当前将导出到另一个工作表 这是我到目前为止的代码 Option Explicit Sub UpdateLogWorksheet() Dim historyWks As Worksheet Dim inputWks As Worksheet Dim nextRow As Long Dim oCol As Long Dim m
Option Explicit
Sub UpdateLogWorksheet()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As String
Dim myCell As Range
'cells to copy from Input sheet - some contain formulas
myCopy = "D5,D7,D9"
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("PartsData")
With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy)
If Application.CountA(myRng) <> myRng.Cells.Count Then
MsgBox "Please fill in all the cells!"
Exit Sub
End If
End With
With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
oCol = 3
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End With
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
它包含用户输入的3个字段,还包含作者和日期/时间,并将其放入xls文档中的工作表中。我希望将此数据发送到另一个指定的电子表格/xls
我们将不胜感激。很抱歉,我不喜欢编码。基本上,您只需要设置两本工作簿的名称,就像设置工作表一样。然后,当您在代码中引用工作表时,假设另一个工作簿与现有工作簿具有相同的工作表名称和结构,则使用您为工作簿提供的变量对其进行处理 上一个问题解释了如何参考工作簿: