|
Sub aaa()
Dim A1 As Worksheet, A2 As Worksheet, p As Integer, ts As Integer, I As Integer, j As Integer
ts = 1
Set A1 = Workbooks("RE_A1.xls").Worksheets("Sheet1")
Set A2 = Workbooks("TRD_Dalyr.xls").Worksheets("Sheet1")
Workbooks("TRD_Dalyr.xls").Worksheets("Sheet2").Select
m = A1.UsedRange.Rows.Count
n = A2.UsedRange.Rows.Count
For I = 2 To m
If Year(A1.Cells(I, 2)) = 2001 Then
For j = 2 To n
If A1.Cells(I, 1) = A2.Cells(j, 1) And A1.Cells(I, 2) = A2.Cells(j, 2) Then
For p = -3 To 2
Cells(ts + 4 + p, 1) = A2.Cells(j + p, 1)
Cells(ts + 4 + p, 2) = A2.Cells(j + p, 2)
Cells(ts + 4 + p, 3) = A2.Cells(j + p, 3)
Cells(ts + 4 + p, 4) = A1.Cells(I, 3)
Next p
ts = ts + 6
End If
Next j
End If
Next I
End Sub
显示 n = A2.UsedRange.Rows.Count 对象变量或with块变量未设置
- Sub aaa()
- Dim A1 As Worksheet, A2 As Worksheet, p As Integer, ts As Integer, I As Integer, j As Integer
- Dim m As Integer, n As Integer
- ts = 1
- On Error Resume Next
- If Workbooks("RE_A1.xls") Is Nothing Then MsgBox "RE_A1.xls未打开": Exit Sub
- Set A1 = Workbooks("RE_A1.xls").Worksheets("Sheet1")
- If A1 Is Nothing Then MsgBox "RE_A1.xls中没有Sheet1工作表": Exit Sub
- If Workbooks("TRD_Dalyr.xls") Is Nothing Then MsgBox "TRD_Dalyr.xls": Exit Sub
- Set A2 = Workbooks("TRD_Dalyr.xls").Worksheets("Sheet1")
- If A2 Is Nothing Then MsgBox "TRD_Dalyr.xls中无Sheet1工作表"
- Workbooks("TRD_Dalyr.xls").Worksheets("Sheet2").Select
- m = A1.UsedRange.Rows.Count
- n = A2.UsedRange.Rows.Count
- For I = 2 To m
- If Year(A1.Cells(I, 2)) = 2001 Then
- For j = 2 To n
- If A1.Cells(I, 1) = A2.Cells(j, 1) And A1.Cells(I, 2) = A2.Cells(j, 2) Then
- For p = -3 To 2
- Cells(ts + 4 + p, 1) = A2.Cells(j + p, 1)
- Cells(ts + 4 + p, 2) = A2.Cells(j + p, 2)
- Cells(ts + 4 + p, 3) = A2.Cells(j + p, 3)
- Cells(ts + 4 + p, 4) = A1.Cells(I, 3)
- Next p
- ts = ts + 6
- End If
- Next j
- End If
- Next I
- End Sub
复制代码
|
|