|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
提示我对象变量或with块变量未设置
主要是想要将jigou这个表里的数据,筛选30天内合约到期的客户,然后新建个子表,将jigou里对应客户的机构ID、机构主体名称、对应服务人员提取到新表中
然后错误的地方,我下面标黄了,我这到底哪里错了?
Sub 三十天内过期客户()
Application.DisplayAlerts = False
Dim del As Worksheet
For Each del In ActiveWorkbook.Worksheets
If del.Name = "30天内到期客户总结" Then
del.Delete
End If
Next
Application.DisplayAlerts = True
'系统查找有没有这个名字的表,有的话就删除
Sheets.Add after:=kanban
ActiveSheet.Name = "30天内到期客户总结"
'新建表格存放数据
Dim lastrow As Integer
Dim rng As Range, rng1 As Range
Dim gr, qr, zr, br As Variant
Dim arr() As Variant
With Sheets(jigou.Name)
lastrow = .Cells.SpecialCells(xlCellTypeLastCell).Row
rng = .Range("A1").CurrentRegion
gr = .Range("1:1").Find("客户分层", , , xlWhole).Column
qr = .Range("1:1").Find("机构ID", , , xlWhole).Column
zr = .Range("1:1").Find("机构主体名称", , , xlWhole).Column
br = .Range("1:1").Find("客户成功人员", , , xlWhole).Column
rng.AutoFilter field:=sr, Criteria1:="1个月内到期客户"
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
lr = rng1.Columns.Count
lc = rng1.Cells.Count / lr
ReDim arr(1 To 3, 1 To lc)
For Each r In rng1.Areas
a = r
For i = 1 To UBound(a)
m = m + 1
For j = 1 To UBound(a, 2)
If m = 1 Then
arr(m, j) = a(qr, j)
ElseIf m = 2 Then
arr(m, j) = a(zr, j)
ElseIf m = 3 Then
arr(m, j) = a(br, j)
End If
Debug.Print arr(m, j)
Next
Next
Next
End With
rng.AutoFilter
Range("A1").Resize(3, lc) = arr
End Sub
|
-
|