excle表用VB编与报表标签(日期)关联的累计值

来源:百度知道 编辑:UC知道 时间:2024/05/23 15:44:59
请高手编一段excle间取数的VB小程序
即:sheet(x)的某列=sheet(x-1)的某列,x为变量

看以下的例子
Private Sub Command1_Click()
Dim i As Integer
Dim ExlApp As Object
Dim ExlBook As Object
Dim ExlSheet1 As Object
Dim ExlSheet2 As Object

Const StartRow = 8
Const EndRow = 44

Set ExlApp = CreateObject("Excel.Application")
Set ExlBook = ExlApp.WorkBooks.Open("d:\复件 2009年5月成本表.xls")
Set ExlSheet1 = ExlBook.WorkSheets(1)
Set ExlSheet2 = ExlBook.WorkSheets(2)

For i = StartRow To EndRow
ExlSheet1.Cells(i, 8).Value = ExlSheet2.Cells(i, 8).Value
ExlSheet1.Cells(i, 9).Value = ExlSheet2.Cells(i, 9).Value
ExlSheet1.Cells(i, 10).Value = ExlSheet2.Cells(i, 10).Value
ExlSheet1.Cells(i, 11).Value = ExlSheet2.Cells(i, 11).Value
Next i

ExlApp.Save
ExlApp.Quit

Set ExlSheet1 = Nothing
Set ExlSheet2 = Nothing
Set ExlBook = Nothing
Set ExlApp = Nothing

MsgBox "完成"
End Sub