我收到了来自每个销售订单的LTest表单,我想从LTest复制某些数据并将其复制到2016 Test 1.每个表单格式相同,我想使用LTest单元格B3中的数据在2016 Test 1中选择适当的选项卡,然后将信息插入同一工作表的相应单元格中。 LTest的名称将因订单而异,我将不得不调整表单以包含也将是唯一的订单号。
一个问题是LTest,2016年测试1是不同的电子表格。
Sub Keysha_Bee()
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim wb2 As Workbook
Dim ws2 As Worksheet
Dim SheetID As String
Dim i As Integer
Dim lrow As Integer
Set wb1 = Workbooks("LTest")
Set ws1 = wb1.Sheets(1)
Set wb2 = Workbooks("2016 Test1")
If InStr(ws1.Range("B3"), "FPPI") > 0 Then SheetID = "FPPI-Routed"
If InStr(ws1.Range("B3"), "USPPI") > 0 Then SheetID = "USPPI-Routed"
If InStr(ws1.Range("B3"), "Standard") > 0 Then SheetID = "Standard"
i = 1
Do Until i > wb2.Sheets.Count
If wb2.Sheets(i).Name = SheetID Then Set ws2 = wb2.Sheets(i) Else GoTo Nexti
lrow = ws2.Cells(Rows.Count, 2).End(xlUp).Row + 1
ws2.Cells(lrow, 2) = ws1.Range("D6") 'Customer Name
If ws2.Range("D14") = "" Then
ws2.Cells(lrow, 3) = ws1.Range("D17") 'Agent's Name
ws2.Cells(lrow, 4) = ws1.Range("D18") 'Auth Agent's Email
Else
ws2.Cells(lrow, 3) = ws1.Range("D15") 'Agent's Name
ws2.Cells(lrow, 4) = ws1.Range("D16") 'Auth Agent's Email
End If
ws2.Cells(lrow, 5) = "NO" 'Routed, not sure what this is supposed to reference
ws2.Cells(lrow, 6) = ws1.Range("D20") ' Routed
ws2.Cells(lrow, 7) = ws1.Range("D26") ' Origin
ws2.Cells(lrow, 8) = ws1.Range("D27") ' Hazardous
ws2.Cells(lrow, 9) = ws1.Range("D28") ' UC Type
ws2.Cells(lrow, 10) = "Date" 'Not sure what this is supposed to refference
Nexti:
i = i + 1
Loop
End Sub
答案 0 :(得分:0)
试试这个(已编辑):
update