简体   繁体   English

将单元格从一个工作簿(非特定)复制到另一个(特定)

[英]Copy cells from one Workbook (non-specific) to another (specific)

Okay, so I'm trying to create an order log for a business (employee usage). 好的,所以我正在尝试为企业(员工使用情况)创建订单日志。

I have a form set out where multiple users can access/input all the information needed. 我有一个表格,其中多个用户可以访问/输入所有需要的信息。 It prints into an Excel spreadsheet for one person to open and place orders from. 它打印到Excel电子表格中,供一个人打开并下订单。 Sometimes a user might want to copy an order line from a previous year's log (there are 4 so far), so I'm trying to incorporate that into the current log. 有时用户可能想从上一年的日志(到目前为止有4条)中复制一条订单行,因此我试图将其合并到当前日志中。

I'm having trouble with referencing another workbook that the user has opened and copying the information into a userform opened in the current log. 我在引用用户已打开的另一个工作簿并将信息复制到在当前日志中打开的用户表单时遇到麻烦。 I have this: 我有这个:

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

So what I want to happen is: 所以我想发生的是:

  1. User opens current order log 用户打开当前订单日志
  2. User presses ActiveX button to open frmOrderLog 用户按下ActiveX按钮打开frmOrderLog
  3. a) User enters information manually a)用户手动输入信息
    b) User copies information from current year's log b)用户从当年的日志中复制信息
    c) User minimizes window, opens previous year's log, selects a cell, and in the userform presses "Copy Order" button which then copies the information from corresponding cells from the previous year's order log into the corresponding text boxes/combo boxes in the form within the current year's order log c)用户最小化窗口,打开上一年的日志,选择一个单元格,然后在用户窗体中按“复制订单”按钮,然后将上一年订单日志中相应单元格中的信息复制到表格中相应的文本框/组合框中在当年的订单日志中

If there is any requirement for clarification, let me know. 如果有任何澄清要求,请告知我。 I'm sorry if this is in the forums already, but using my search terms I could not find answers that helped. 很抱歉,如果这已经在论坛中了,但是使用搜索字词我找不到有帮助的答案。

Seems like a simple syntax issue to me: 对我来说似乎是一个简单的语法问题:

you want to change: 您要更改:

If ActiveWorkbook.Sheet1.Cells(2, x).Text = "Item" Then

To: 至:

If ActiveWorkbook.Sheets(1).Cells(2, x).Text = "Item" Then

The Sheet1 syntax didn't work for me. Sheet1语法对我不起作用。

And obviously you want to make the same change wherever else Sheet1 occurs. 很显然,无论其他Sheet1发生在哪里,您都希望进行相同的更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在一个工作簿中查找和 Select 个具有特定文本的单元格并复制到另一个工作簿 - Find and Select cells with specific text in one workbook and copy to another workbook 如何使用C#将一个Excel工作簿中特定范围的单元格复制到另一工作簿中 - how to copy cells from a specific range from one excel workbook to another workbook using c# VBscript:将数据从一个工作簿复制/粘贴到另一工作簿的下一个空白行(特定单元格) - VBscript: Copy/Paste data from one workbook to next blank row (specific cells) of another workbook 将特定行从一个工作簿复制到另一个工作簿 - Copy specific Rows from one workbook to another 根据条件将特定单元格从一个工作簿复制到另一个工作簿的不同单元中 - Copy specific cells from one workbook to different cells in another depending on condition excel宏有条件地复制另一个工作簿中的特定单元格 - excel macro to conditionally copy specific cells from another workbook 从一个工作簿复制到另一个工作簿中的特定工作表 - Copy from one workbook to specific sheet in another workbook Excel VBA:将特定工作簿中的单元格循环复制到另一个 - Excel VBA: Copy cells from specific workbook in loop to another 如何使用 VBA 将基于某些条件的粘贴数据从一个工作簿复制到另一个工作簿(特定单元格)? - How to copy paste data based on some criterias from one workbook to another(specific cells) using VBA? 将特定内容从一个excel工作簿复制到另一工作簿 - copy specific content from one excel workbook to another workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM