|
新手不会写了!求大神解答!
先按起始日期查找符合条件的Sheet1的春节个数日期写入表2 A2单元格以下
按春节查找SHEET2 A列日期符合条件的最大值日期行 所对应的值!
自己写的代码春节日期好像是对的,但后面对应值的和不会写乱加的!
Sub abc()
Dim ks, js, arr, arr1, xmax, n, i, ic, cjrq, brr
ks = Sheet2.[j3]: js = Sheet2.[j4] '起始日期
arr = Sheet2.Range("a6:a" & Sheet2.Range("a600").End(xlUp).Row) '日期
arr1 = Sheet1.Range("a7:a98")
ReDim brr(1 To 100, 1 To 1)
For ic = 1 To UBound(arr1)
If arr1(ic, 1) >= ks And arr1(ic, 1) <= js Then '起始日期内的春节日期
n = n + 1
brr(n, 1) = arr1(ic, 1)
For i = 1 To UBound(arr)
If arr(i, 1) < brr(n, 1) Then
xmax = Application.WorksheetFunction.Max(arr)
End If
Next
Sheet2.Range("a2").Resize(n, 1) = brr
Sheet2.Range("c2").Resize(n, 1) = xmax.Offset(0, 2)
Sheet2.Range("d2").Resize(n, 1) = xmax.Offset(0, 3)
'MsgBox s
'MsgBox Format(xmax, "YYYY-MM-DD")
End If
Next
End Sub
|
|