Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2348|回复: 4

[已解决]求助:类型不匹配

[复制链接]
发表于 2010-1-11 16:14 | 显示全部楼层 |阅读模式

ubb3cfcV.rar (33.1 KB, 下载次数: 0)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2010-1-11 18:09 | 显示全部楼层

因为ardt数据有空,在判断日期时提示不匹配,改为红的部份试试

Sub ff()
Dim arDt As Variant
Dim arRe() As Variant
Dim oDic As Object
Dim daSta As Date
Dim daStp As Date
Dim bDate As Boolean
Dim iDct As Integer
Dim iTmp As Integer
Dim i As Integer
Range("A2:D177").ClearContents
With Sheet1
    arDt = .Range("a3:f" & .[a65536].End(3).Row)
End With

'arDt = Sheet1.Range("a3").CurrentRegion
ReDim arRe(1 To UBound(arDt), 1 To 4)
daSta = Range("f3").Value
daStp = Range("h3").Value
Set oDic = CreateObject("scripting.dictionary")
For i = 4 To UBound(arDt)
    bDate = (DateValue(arDt(i, 1)) >= daSta) And (DateValue(arDt(i, 1)) <= daStp)
    If bDate Then
        iTmp = oDic(arDt(i, 3) & arDt(i, 4))
        If iTmp = 0 Then
            iDct = iDct + 1
            oDic(arDt(i, 3) & arDt(i, 4)) = iDct
            iTmp = iDct
        End If
         arRe(iTmp, 1) = iTmp
         arRe(iTmp, 2) = arDt(i, 3)
         arRe(iTmp, 3) = arDt(i, 4)
         arRe(iTmp, 4) = arRe(iTmp, 4) + arDt(i, 5)
   End If
Next
[a2].Resize(iDct, 4) = arRe
End Sub

回复

使用道具 举报

发表于 2010-1-11 18:19 | 显示全部楼层

CurrentRegion不能用于设置保护的工作表,会产生N多空数据

回复

使用道具 举报

 楼主| 发表于 2010-1-12 08:18 | 显示全部楼层

QUOTE:
以下是引用雨狐在2010-1-11 18:09:00的发言:

因为ardt数据有空,在判断日期时提示不匹配,改为红的部份试试

Sub ff()
Dim arDt As Variant
Dim arRe() As Variant
Dim oDic As Object
Dim daSta As Date
Dim daStp As Date
Dim bDate As Boolean
Dim iDct As Integer
Dim iTmp As Integer
Dim i As Integer
Range("A2:D177").ClearContents
With Sheet1
    arDt = .Range("a3:f" & .[a65536].End(3).Row)
End With

'arDt = Sheet1.Range("a3").CurrentRegion
ReDim arRe(1 To UBound(arDt), 1 To 4)
daSta = Range("f3").Value
daStp = Range("h3").Value
Set oDic = CreateObject("scripting.dictionary")
For i = 4 To UBound(arDt)
    bDate = (DateValue(arDt(i, 1)) >= daSta) And (DateValue(arDt(i, 1)) <= daStp)
    If bDate Then
        iTmp = oDic(arDt(i, 3) & arDt(i, 4))
        If iTmp = 0 Then
            iDct = iDct + 1
            oDic(arDt(i, 3) & arDt(i, 4)) = iDct
            iTmp = iDct
        End If
         arRe(iTmp, 1) = iTmp
         arRe(iTmp, 2) = arDt(i, 3)
         arRe(iTmp, 3) = arDt(i, 4)
         arRe(iTmp, 4) = arRe(iTmp, 4) + arDt(i, 5)
   End If
Next
[a2].Resize(iDct, 4) = arRe
End Sub

你好,我按你的方式改了,可是还是出现了类型不匹配,请帮忙查看一下,谢谢!

回复

使用道具 举报

发表于 2010-1-12 08:43 | 显示全部楼层    本楼为最佳答案   

这样就好了

Sub ff()
Dim arDt As Variant
Dim arRe() As Variant
Dim oDic As Object
Dim daSta As Date
Dim daStp As Date
Dim bDate As Boolean
Dim iDct As Integer
Dim iTmp As Integer
Dim i As Integer
Range("A2:D177").ClearContents
arDt = Sheet1.Range("a3").CurrentRegion
ReDim arRe(1 To UBound(arDt), 1 To 4)
daSta = Range("f3").Value
daStp = Range("h3").Value
Set oDic = CreateObject("scripting.dictionary")
For i = 4 To UBound(arDt)
    If Len(arDt(i, 1)) = 0 Then Exit For
    bDate = (DateValue(arDt(i, 1)) >= daSta) And (DateValue(arDt(i, 1)) <= daStp)
    If bDate Then
        iTmp = oDic(arDt(i, 3) & arDt(i, 4))
        If iTmp = 0 Then
            iDct = iDct + 1
            oDic(arDt(i, 3) & arDt(i, 4)) = iDct
            iTmp = iDct
        End If
         arRe(iTmp, 1) = iTmp
         arRe(iTmp, 2) = arDt(i, 3)
         arRe(iTmp, 3) = arDt(i, 4)
         arRe(iTmp, 4) = arRe(iTmp, 4) + arDt(i, 5)
   End If
Next
[a2].Resize(iDct, 4) = arRe
End Sub

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-6 10:51 , Processed in 0.602200 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表