![](/img/trans.png)
[英]Find and Select cells with specific text in one workbook and copy to another workbook
[英]Copy cells from one Workbook (non-specific) to another (specific)
好的,所以我正在嘗試為企業(員工使用情況)創建訂單日志。
我有一個表格,其中多個用戶可以訪問/輸入所有需要的信息。 它打印到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
所以我想發生的是:
如果有任何澄清要求,請告知我。 很抱歉,如果這已經在論壇中了,但是使用搜索字詞我找不到有幫助的答案。
對我來說似乎是一個簡單的語法問題:
您要更改:
If ActiveWorkbook.Sheet1.Cells(2, x).Text = "Item" Then
至:
If ActiveWorkbook.Sheets(1).Cells(2, x).Text = "Item" Then
Sheet1語法對我不起作用。
很顯然,無論其他Sheet1發生在哪里,您都希望進行相同的更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.