|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub drCmd_Click()
Dim col As Long
col = Sheets("全月").Range("E2").End(xlToRight).Column
Dim rqRange As Range
Dim rqStr As String
For Each rqRange In Sheets("全月").Range(Cells(2, 5), Cells(2, col))
rqStr = Month(rqRange) & "." & Day(rqRange)
If Sheets("全月").Cells(3, rqRange.Column) = "" Then
Call drData(rqStr, rqRange.Column)
End If
Next
End Sub
Public Function drData(str As String, num As Long)
Dim FileStr As String
FileStr = ThisWorkbook.Path & "\MCD CRM Daily Market New Member Report-" & str & ".xlsx"
Dim s As String
s = Dir(FileStr)
If s = "" Then Exit Function
Application.ScreenUpdating = False
Dim wb As Workbook
Dim ws As Worksheet
Set wb = Workbooks.Open(FileStr)
Set ws = wb.Sheets("新增会员数据")
Dim r1 As Range
Dim r2 As Range
Dim row1 As Long
Dim row2 As Long
row1 = ThisWorkbook.Sheets("全月").Range("B2").End(xlDown).Row
row2 = ws.Range("E50000").End(xlUp).Row
For Each r1 In ThisWorkbook.Sheets("全月").Range("B3:B" & row1)
Set r2 = ws.Range("E6:E" & row2).Find(r1, , , xlWhole)
If r2 Is Nothing Then
ThisWorkbook.Sheets("全月").Cells(r1.Row, num).Value = 0
Else
ThisWorkbook.Sheets("全月").Cells(r1.Row, num).Value = r2.Offset(0, 2)
End If
Next
wb.Close
Application.ScreenUpdating = True
Set wb = Nothing
Set ws = Nothing
End Function
刚帮人做了个类似的, 既然你会写, 可以看着改改...... |
|