Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1322402
  • 博文数量: 124
  • 博客积分: 5772
  • 博客等级: 大校
  • 技术积分: 1647
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-27 10:39
文章分类

全部博文(124)

文章存档

2020年(1)

2019年(1)

2018年(5)

2017年(2)

2016年(17)

2015年(3)

2014年(7)

2013年(11)

2012年(13)

2011年(30)

2010年(34)

分类: WINDOWS

2010-09-27 11:10:16

Private Sub Command1_Click()
    Dim sxlApp As Excel.Application
    Dim sxlBook As Excel.Workbook
    Dim sxlSheet As Excel.Worksheet '打开EXCEL文件
    Dim dxlApp As Excel.Application
    Dim dxlBook As Excel.Workbook
    Dim dxlSheet As Excel.Worksheet '打开另一个EXCEL文件
    Set sxlApp = CreateObject("Excel.Application")
    Set sxlBook = sxlApp.Workbooks.Open("d:\source.xls") '打开source.xls
    sxlApp.Visible = True
    Set dxlApp = CreateObject("Excel.Application")
    Set dxlBook = sxlApp.Workbooks.Open("d:\dest.xls") '打开dest.xls
    dxlApp.Visible = True
    Set sxlSheet = sxlBook.Worksheets(1)
    sxlSheet.Activate
    Set dxlSheet = dxlBook.Worksheets(1)
    dxlSheet.Activate
    Dim i%, j%, k%
    Dim d As String, s As String
    For i = 148 To 220 '在dest中遍历
        d = dxlSheet.Cells(i, 2)
        For j = 2 To 480
            s = sxlSheet.Cells(j, 4)
            If s = d Then
                For k = 5 To 35
                    dxlSheet.Cells(i, k) = dxlSheet.Cells(i, k) + sxlSheet.Cells(j, k + 8)
                Next k
                'Exit For
            End If
        Next j
    Next i
    MsgBox "write OK!"
End Sub


阅读(2150) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~