Excel精英培训网

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

[已解决]为什么K列,K40不添加F列数据???正确结果如M40。

[复制链接]
发表于 2013-5-30 10:21 | 显示全部楼层 |阅读模式
Option Explicit

Sub test()
Dim a, i, arr, isflag, diction
isflag = False
Set diction = CreateObject("scripting.dictionary")
a = Cells(200000, 2).End(xlUp).Row
arr = Cells(1, 2).Resize(a, 7)
For i = 1 To a
diction(Replace(arr(i, 1), "0", "")) = arr(i, 7)
Next i
Erase arr
a = Cells(200000, 1).End(xlUp).Row
arr = Cells(1, 1).Resize(a)
For i = 1 To a
If arr(i, 1) = "%" Then isflag = True
If isflag Then
If diction.exists(arr(i, 1)) Then
If diction(arr(i, 1)) <> "" Then arr(i, 1) = arr(i, 1) & [h1] & diction(arr(i, 1))
End If
End If
Next i
[k1].Resize(a) = arr
End Sub

这个数据源
为什么K列,K40不添加F列数据???正确结果如M40。帮我改一下,谢谢!!!
最佳答案
2013-5-30 14:14
本帖最后由 zjdh 于 2013-5-30 14:16 编辑

Sub test()
    Dim a, i, arr, isflag, diction
    isflag = False
    Set diction = CreateObject("scripting.dictionary")
    a = Cells(200000, 2).End(xlUp).Row - 2
    arr = Cells(3, 2).Resize(a, 7)
    For i = 1 To a
        If arr(i, 1) = "" Then Exit For   
        diction("T" & Val(Split(arr(i, 1), "T")(1))) = arr(i, 7)
    Next i
    Erase arr
    a = Cells(200000, 1).End(xlUp).Row
    arr = Cells(1, 1).Resize(a)
    For i = 1 To a
        If arr(i, 1) = "%" Then isflag = True
        If isflag Then
            If diction.exists(arr(i, 1)) Then
                If diction(arr(i, 1)) <> "" Then arr(i, 1) = arr(i, 1) & [h1] & diction(arr(i, 1))
            End If
        End If
    Next i
    [k1].Resize(a) = arr
End Sub

条件替换问题.rar

402.61 KB, 下载次数: 17

发表于 2013-5-30 14:14 | 显示全部楼层    本楼为最佳答案   
本帖最后由 zjdh 于 2013-5-30 14:16 编辑

Sub test()
    Dim a, i, arr, isflag, diction
    isflag = False
    Set diction = CreateObject("scripting.dictionary")
    a = Cells(200000, 2).End(xlUp).Row - 2
    arr = Cells(3, 2).Resize(a, 7)
    For i = 1 To a
        If arr(i, 1) = "" Then Exit For   
        diction("T" & Val(Split(arr(i, 1), "T")(1))) = arr(i, 7)
    Next i
    Erase arr
    a = Cells(200000, 1).End(xlUp).Row
    arr = Cells(1, 1).Resize(a)
    For i = 1 To a
        If arr(i, 1) = "%" Then isflag = True
        If isflag Then
            If diction.exists(arr(i, 1)) Then
                If diction(arr(i, 1)) <> "" Then arr(i, 1) = arr(i, 1) & [h1] & diction(arr(i, 1))
            End If
        End If
    Next i
    [k1].Resize(a) = arr
End Sub
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 12:09 , Processed in 0.254467 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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