我想比较两个excel工作簿数据,我写了代码,但给出了运行时错误,给我一个值w值

时间:2017-03-29 18:15:35

标签: excel excel-vba vba

Sub Click()
Dim vFile As Variant
Dim wbCopyTo As Workbook
Dim wsCopyTo As Worksheet
Dim wbCopyFrom As Workbook
Dim wsCopyFrom As Worksheet
Set wbCopyTo = ActiveWorkbook
Set wsCopyTo = ActiveSheet
'-------------------------------------------------------------
'Open file with data to be copied
vFile = Application.GetOpenFilename("Excel Files (*.xlsx*)," & _"*.xlsx*", 1, "Select Excel File", "Open", False)
'If Cancel then Exit
If TypeName(vFile) = "Boolean" Then
Exit Sub
Else
Set wbCopyFrom = Workbooks.Open(vFile)
Set wsCopyFrom = wbCopyFrom.Worksheets("Corrosion")
End If
 '--------------------------------------------------------------
'comparing data and copy range
Dim n, i, j, k, l, o, w, s As Double
n = wbCopyFrom.Worksheets("Corrosion").Cells(12, 3).Value
s = wbCopyFrom.Worksheets("Corrosion").Cells(22 + k, 3).Value
w = wbCopyTo.ActiveSheet("Investigation Summary").Cells(8045 + j, 5).Value
If (w = s) Then
o = 8 + j
dbln = "Y" & o
dblq = "BB" & o
dblt = "BK" & o
dblu = "BM" & o
wsCopyFrom.Range(dblm, dblp).Copy
wsCopyTo.Range(dbln, dblq).PasteSpecial Paste:=xlPasteValues
i = i + 1
k = k + 1
l = l + 1
o = 8 + j
End If
'----------------------------------------
j = j + 1
Loop
wbCopyFrom.Close SaveChanges:=False
End Sub

0 个答案:

没有答案