我有几个工作簿从一个主工作簿中获取副本。我想要做的是当我将数据输入到主工作簿中时,我想将其复制到另一个工作簿中,该工作簿基于从Combobox1.Value获得的产品类型。要更清楚,我想要复制数据的工作簿取决于ComboBox1.value。即如果ComboBox1.value等于“Penofix”,那么我想将数据复制到工作簿“Penofix.xlsm”。我已经完成了关于如何根据某些条件将数据输入到特定行的主输入上的编码,但是面临将数据复制到其他工作簿的问题。如何将行和列复制到另一个工作簿上的另一个工作表
Private Sub CmdEnter_Click()
Dim CountRow As Long
Dim i As Long
Dim prod as string
Dim j As Long
Dim Ws As Worksheet
Dim Count1 as Long
'CountRow is number of row in master workbook
CountRow = Worksheets("Input").Range("B" & Rows.Count).End(xlUp).Row
'assign variable prod with combobox1 value
prod = ComboBox1.Value
'i=32 because my row start at 32
For i = 32 To countRow + 31
While ComboBox1.Value = Worksheets("Input").Cells(i, 2).Value
Rows(i).Select
Selection.Insert shift = xlDown
With Worksheets("Input")
'insert data into master workbook
.Range("B" & i) = ComboBox1.Text
.Range("C" & i) = TextBox1.Text
.Range("D" & i) = TextBox2.Text
.Range("E" & i) = TextBox3.Text
.Range("F" & i) = TextBox4.Text
.Range("G" & i) = TextBox5.Text
.Range("H" & i) = ComboBox2.Text
.Range("I" & i) = TextBox6.Text
.Range("J" & i) = TextBox7.Text
.Range("K" & i) = TextBox8.Text
End With
'activate other workbook to copy data,if prod = Penofix,the workbook will be "Penofix.xlsm"
workbooks(prod & ".xlsm").Activate
'count the number of row in workbooks(prod & ".xlsm").
' i specified cell (31,3) to calculate the number of row used
Count1 = Workbooks(prod & ".xlsm").Worksheets("Sheet1").Cells(31,3).Value
Count1 = Count1 + 31
'copy data into workbooks(prod & ".xlsm")
'THIS IS THE LINE WHICH ERROR
Workbooks(prod & ".xlsm").Worksheets("Input").Range(Cells(Count1, 2), Cells(Count1 , 11)).Value = Workbooks("Master.xlsm").Worksheets("Input").Range(Cells(i, 2), Cells(i, 11)).Value
If MsgBox("One record written to Input. Do you want to continue entering data?", vbYesNo)= vbYes Then
ComboBox1.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
ComboBox2.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
Else
Unload Me
End If
Exit Sub
Wend
Next
End Sub
我已经尝试用这种
Workbooks(prod & ".xlsm").Worksheets("Input").Cells(Count1, 2).Value = Workbooks("Master.xlsm").Worksheets("Input").Cells(i, 2).Value
更换
Workbooks(prod & ".xlsm").Worksheets("Input").Range(Cells(Count1, 2), Cells(Count1 , 11)).Value = Workbooks("Master.xlsm").Worksheets("Input").Range(Cells(i, 2), Cells(i, 11)).Value
和是唯一只为一个烧毛细胞的工作,但它。所以,我认为错误是语法:
Range(Cells(Count1,2), Cells(Count1,11))
但我不知道如何使它整行
我会评价这种类型的Excel-VBA问题,因为这里最常见的问题类别。你只能说你有一个问题将数据复制到另一个表单。*,什么是确切的问题? '1.'错误? '''''只是不确定代码片段? – bonCodigo 2013-02-26 07:21:35
@bonCodigo我已经更新了我所做的问题和编码。但仍然会出错。或者你仍然不清楚我的问题是什么? – 2013-02-26 08:45:48
你有什么错误? – glh 2013-02-26 10:54:46