好的,所以我正在尝试为企业创建订单日志(员工使用情况)。
我有一个表单,其中多个用户可以访问/输入所需的所有信息。它打印到Excel电子表格中供一个人打开和下订单。有时用户可能希望从前一年的日志中复制订单行(到目前为止有4个),所以我试图将其合并到当前日志中。
我在引用用户已打开的另一个工作簿时遇到问题,并将信息复制到当前日志中打开的用户窗体中。我有这个:
Private Sub cmdCopy_Click()
Dim rowRef As Integer, colItem As Integer, colSup As Integer, colCatNum As Integer, colQty As Integer, colUnit As Integer, colCat As Integer
'stores row of selected order from old order log successfully
rowRef = ActiveCell.row
'I'm trying to find which column has which headers as the logs aren't consistent
For x = 2 To 9
If ActiveWorkbook.Sheet1.Cells(2, x).Text = "Item" Then
colItem = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Supplier" Then
colSup = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Catalogue #" Then
colCatNum = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Qty" Then
colQty = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Unit" Then
colUnit = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Category" Then
colCat = x
End If
Next x
'fills information into userform
txtItem.Text = Sheet1.Cells(rowRef, colItem).Text
txtSup.Text = Sheet1.Cells(rowRef, colSup).Value
txtCatNum.Text = Sheet1.Cells(rowRef, colCatNum).Value
txtQty.Text = Sheet1.Cells(rowRef, colQty).Value
cboUnit.Text = Sheet1.Cells(rowRef, colUnit).Value
cboCat.Text = Sheet1.Cells(rowRef, colCat).Value
End Sub
所以我想要发生的是:
如果有任何澄清要求,请告诉我。我很抱歉,如果这已经在论坛中,但使用我的搜索字词,我找不到有帮助的答案。
答案 0 :(得分:1)
对我来说似乎是一个简单的语法问题:
你想改变:
If ActiveWorkbook.Sheet1.Cells(2, x).Text = "Item" Then
要:
If ActiveWorkbook.Sheets(1).Cells(2, x).Text = "Item" Then
Sheet1语法对我不起作用。
显然你想在Sheet1发生的任何地方做同样的改变。