主题:向各们大侠请教
我有两份数据,一份是作物资料,一份是经纬度,我想通过两份数据的编号,将数据匹配在一起,下面是我的程序,不知道哪儿出错了,请好心人帮忙
Dim xlapp1 As Excel.Application
Dim xlapp2 As Excel.Application
Dim xlbook1 As Excel.Workbook
Dim xlbook2 As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim i As Long
Dim j As Long
Private Sub Command1_Click()
Set xlapp1 = CreateObject("Excel.Application")
Set xlbook1 = xlapp1.Workbooks.Open("e:\气候区划\数据整理\作物资料--1\作物发育资料--1.xlsx")
Set xlsheet1 = xlbook1.Worksheets(1)
Set xlapp2 = CreateObject("Excel.Application")
Set xlbook2 = xlapp2.Workbooks.Open("E:\气候区划\数据整理\作物资料--1\农气站经纬度.xlsx")
Set xlsheet2 = xlbook2.Worksheets(1)
For i = 1 To 285433
For j = 1 To 779
If xlsheet1.cells(i, 1) = xlsheet2.cells(j, 2) Then
xlsheet1.cells(i, 24) = xlsheet2.cells(j, 2)
xlsheet1.cells(i, 25) = xlsheet2.cells(j, 3)
xlsheet1.cells(i, 26) = xlsheet2.cells(j, 4)
xlsheet1.cells(i, 27) = xlsheet2.cells(j, 5)
xlsheet1.cells(i, 28) = xlsheet2.cells(j, 6)
Else
xlsheet1.cells(i, 24) = -9999
xlsheet1.cells(i, 25) = -9999
xlsheet1.cells(i, 26) = -9999
xlsheet1.cells(i, 27) = -9999
xlsheet1.cells(i, 28) = -9999
End If
Next j
Next i
xlbook1.Close
xlbook2.Close
xlapp1.Quit
xlapp2.Quit
Set xlapp1 = Nothing
Set xlapp2 = Nothing
Set xlbook1 = Nothing
Set xlbook2 = Nothing
Set xlsheet1 = Nothing
Set xlsheet2 = Nothing
End
End Sub
Dim xlapp1 As Excel.Application
Dim xlapp2 As Excel.Application
Dim xlbook1 As Excel.Workbook
Dim xlbook2 As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim i As Long
Dim j As Long
Private Sub Command1_Click()
Set xlapp1 = CreateObject("Excel.Application")
Set xlbook1 = xlapp1.Workbooks.Open("e:\气候区划\数据整理\作物资料--1\作物发育资料--1.xlsx")
Set xlsheet1 = xlbook1.Worksheets(1)
Set xlapp2 = CreateObject("Excel.Application")
Set xlbook2 = xlapp2.Workbooks.Open("E:\气候区划\数据整理\作物资料--1\农气站经纬度.xlsx")
Set xlsheet2 = xlbook2.Worksheets(1)
For i = 1 To 285433
For j = 1 To 779
If xlsheet1.cells(i, 1) = xlsheet2.cells(j, 2) Then
xlsheet1.cells(i, 24) = xlsheet2.cells(j, 2)
xlsheet1.cells(i, 25) = xlsheet2.cells(j, 3)
xlsheet1.cells(i, 26) = xlsheet2.cells(j, 4)
xlsheet1.cells(i, 27) = xlsheet2.cells(j, 5)
xlsheet1.cells(i, 28) = xlsheet2.cells(j, 6)
Else
xlsheet1.cells(i, 24) = -9999
xlsheet1.cells(i, 25) = -9999
xlsheet1.cells(i, 26) = -9999
xlsheet1.cells(i, 27) = -9999
xlsheet1.cells(i, 28) = -9999
End If
Next j
Next i
xlbook1.Close
xlbook2.Close
xlapp1.Quit
xlapp2.Quit
Set xlapp1 = Nothing
Set xlapp2 = Nothing
Set xlbook1 = Nothing
Set xlbook2 = Nothing
Set xlsheet1 = Nothing
Set xlsheet2 = Nothing
End
End Sub