|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
下面是我写的代码,没有报错,但是没有结果,请高手帮忙看看哪里有问题
Sub 数据更新()
Dim wb As Workbook '订单工作簿
Dim sb As Workbook '源工作簿
Dim DingDan As Worksheet '日出货订单
Dim Sheet1 As Worksheet '源工作簿源表
Dim i As Integer '订单管理表行数
Dim j As Integer '订单管理表列数
Dim x As Integer '源表行数
Dim y As Integer '源表列数
'指定工作簿和工作表
Application.ScreenUpdating = False
Set wb = ThisWorkbook
Set sb = Workbooks.Open("C:\S.xlsx")
Set DingDan = wb.Worksheets("Sheet1")
Set Sheet1 = sb.Worksheets("Sheet1")
'通过项目行匹配和列匹配
For x = 2 To 23 '从源表中取项目,从头到尾取数
For i = 2 To 27 '从目标表中取项目,从头到尾取数
If Sheet1.Cells(x, 1) = DingDan.Cells(i, 32) Then '判断源表项目和目标表项目是否相同,相同则开始进行对列字段的匹配
For y = 3 To 11 '从源表中取列字段,从左到右取数
For j = 1 To 30 '从目标表中取列项目,从左到右取数
If Sheet1.Cells(1, y) = DingDan.Cells(1, j) Then '判断源表项目和目标表列字段是否相同
DingDan.Cells(i, j).Value = Sheet1.Cells(x, y).Value '源表和目标表行号和列号对应单元格值进行取数
End If
Next j
Next y
End If
Next i
Next x
Application.ScreenUpdating = Ture
Set wb = Nothing
Set sb = Nothing
Set DingDan = Nothing
Set Sheet1 = Nothing
MsgBox "取数完毕!"
End Sub
|
-
-
S.rar
29.46 KB, 下载次数: 10
表和目标表
|