Excel精英培训网

 找回密码
 注册
查看: 5355|回复: 19

[习题] 【字典201201班】A组(A01—A22)第3讲作业上交贴

  [复制链接]
发表于 2012-6-13 14:36 | 显示全部楼层 |阅读模式
本帖最后由 liuguansky 于 2012-6-21 08:44 编辑

注意:
      
1:作业尽量通过自己思考独立完成,不会的可在同学之间私聊讨论,禁止在QQ群公开讨论。
       2:本帖已经设置仅作者可见,作业可以以压缩附件形式或者直接贴代码提交。(压缩文件名格式:第1讲-A01-论坛ID)
       3:非本组学员作业不得交于此处,不得为抢沙发而占位,不得跟灌水帖,违者扣分。
       4:上交作业截止时间:2012年6月19日18:00。
       5:补交作业截止时间:2012年6月20日18:00。(只记考勤,不做批改)

评分

参与人数 1 +18 收起 理由
xdwy81129 + 18 辛苦学委了

查看全部评分

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-6-15 15:10 | 显示全部楼层
第一次沙发交作业 201201字典班第三讲作业-心灯芯.rar (15.07 KB, 下载次数: 20)

点评

第一题,如果只有一个已知地区就会测试出错,位置设置有误;反向思维,反过来比较[与我一样的想法]; 第二题 ,不错。  发表于 2012-6-20 13:09

评分

参与人数 1 +8 收起 理由
liuguansky + 8 3+5

查看全部评分

回复

使用道具 举报

发表于 2012-6-15 19:12 | 显示全部楼层
本帖最后由 panan12320 于 2012-6-15 21:07 编辑

第一题
Sub dfg()
    Dim i%, a1(), a2()
    Set d = CreateObject("scripting.dictionary")
    Sheets("题2").Range("e2:f65536").ClearContents
    a1 = Range("a2:b" & Range("a65536").End(3).Row)
    a2 = Range("d2:e" & Range("e65536").End(3).Row)
    Range("D1:F65536").Font.Bold = False
    k = UBound(a2, 1)
    For i = 1 To UBound(a2, 1)
        d(a2(i, 1)) = a2(i, 2)
        d(a2(i, 2)) = "0"
    Next
    For i = 1 To UBound(a1, 1)
        If d.exists(a1(i, 1)) Then
            d(a1(i, 1)) = d(a1(i, 1)) + a1(i, 2)
        Else
            k = k + 1
            d.Add k, a1(i, 1)
            d.Add a1(i, 1), a1(i, 2)
        End If
    Next
    ReDim a3(1 To d.Count / 2, 1 To 3)
    For i = 1 To d.Count / 2
        a3(i, 1) = i
        a3(i, 2) = d(i)
        a3(i, 3) = d(a3(i, 2))
    Next
    [d2].Resize(UBound(a3, 1), UBound(a3, 2)) = a3
    Range("D" & UBound(a2, 1) + 2 & ":F" & Range("e65536").End(3).Row + 1).Font.Bold = True
End Sub

第二题

Sub UI()
Dim i%, arr()
    Set d = CreateObject("scripting.dictionary")
    Sheets("题2").Range("e2:f65536").ClearContents
    arr = Range("a2:b" & Range("a65536").End(3).Row)
    For i = 1 To UBound(arr, 1)
        If arr(i, 1) = "" Then arr(i, 1) = arr(i - 1, 1)
        If arr(i, 2) >= [c2] And arr(i, 2) <= [d2] Then
            d(arr(i, 1)) = d(arr(i, 1)) + arr(i, 2)
        End If
    Next
    [E2].Resize(d.Count, 1) = Application.Transpose(d.keys)
    [F2].Resize(d.Count, 1) = Application.Transpose(d.items)
End Sub
重新写了第一题

Sub du()
    Dim i%, a1(), a2(), a3(1 To 6000, 1 To 3)
    Set d = CreateObject("scripting.dictionary")
    Sheets("题2").Range("e2:f65536").ClearContents
    a1 = Range("a2:b" & Range("a65536").End(3).Row)
    a2 = Range("d2:e" & Range("e65536").End(3).Row)
    Range("D1:F65536").Font.Bold = False
    k = UBound(a2, 1)
    For i = 1 To UBound(a2, 1)
        d(a2(i, 2)) = a2(i, 1)
        a3(d(a2(i, 2)), 1) = a2(i, 1)
        a3(d(a2(i, 2)), 2) = a2(i, 2)
    Next
    For i = 1 To UBound(a1, 1)
        If d.exists(a1(i, 1)) Then
            a3(d(a1(i, 1)), 3) = a3(d(a1(i, 1)), 3) + a1(i, 2)
        Else
            d(a1(i, 1)) = d.Count + 1
            a3(d(a1(i, 1)), 1) = d(a1(i, 1))
            a3(d(a1(i, 1)), 2) = a1(i, 1)
            a3(d(a1(i, 1)), 3) = a3(d(a1(i, 1)), 3) + a1(i, 2)
        End If
    Next
    [d2].Resize(UBound(a3, 1), UBound(a3, 2)) = a3
    Range("D" & UBound(a2, 1) + 2 & ":F" & Range("e65536").End(3).Row + 1).Font.Bold = True
End Sub

第3讲-A09-panan12320.rar

14.7 KB, 下载次数: 15

评分

参与人数 1 +11 收起 理由
liuguansky + 11

查看全部评分

回复

使用道具 举报

发表于 2012-6-15 20:11 | 显示全部楼层
第一题:
  1. Sub ek_sky()
  2. Dim arr1, arr2, arr3
  3. Dim i&, j&, k&, l&
  4. Dim d1 As New Dictionary
  5. arr1 = Range("D2:E9")
  6. arr2 = Range("A1").CurrentRegion
  7.     For i = 1 To 8
  8.     d1(arr1(i, 2)) = 0
  9.     Next i
  10.         For j = 2 To UBound(arr2)
  11.         d1(arr2(j, 1)) = d1(arr2(j, 1)) + arr2(j, 2)
  12.         Next j
  13.             Range("E2").Resize(d1.Count) = Application.Transpose(d1.Keys)
  14.             Range("F2").Resize(d1.Count) = Application.Transpose(d1.Items)
  15. ReDim arr3(1 To d1.Count, 1 To 1)
  16.         For k = 1 To d1.Count
  17.         arr3(k, 1) = k
  18.         Next k
  19. Range("D2").Resize(d1.Count) = arr3
  20.     For l = 2 To d1.Count + 1
  21.         If l > 8 Then
  22.             Range("D" & l & ":F" & l).Font.Bold = True
  23.         End If
  24.     Next l
  25.     Set arr1 = Nothing
  26.         Set arr2 = Nothing
  27.             Set d1 = Nothing
  28. End Sub
复制代码
第二题:
  1. Sub ek_kw()
  2. Dim arr1, arr2, arr3
  3. Dim i&, j&
  4. Dim d2 As New Dictionary
  5. arr1 = Range("A1:B" & Cells(Rows.Count, 2).End(3).Row)
  6. arr2 = Range("C2:D2")
  7.     For i = 2 To UBound(arr1)
  8.         If arr1(i, 1) = "" Then
  9.             arr1(i, 1) = arr1(i - 1, 1)
  10.                 End If
  11.     Next i
  12.     For j = 2 To UBound(arr1)
  13.         If arr1(j, 2) >= arr2(1, 1) And arr1(j, 2) <= arr2(1, 2) Then
  14.             d2(arr1(j, 1)) = d2(arr1(j, 1)) + arr1(j, 2)
  15.                 End If
  16.     Next j
  17. Range("E2").Resize(d2.Count) = Application.Transpose(d2.Keys)
  18. Range("F2").Resize(d2.Count) = Application.Transpose(d2.Items)
  19. Set arr1 = Nothing
  20.     Set arr2 = Nothing
  21.         Set d2 = Nothing
  22. End Sub
复制代码

点评

第一题,多次循环,思维有点混乱;第二题,两个循环。[1.缩进!!2.数组ERASE]  发表于 2012-6-20 13:05

评分

参与人数 1 +9 收起 理由
liuguansky + 9 4+5

查看全部评分

回复

使用道具 举报

发表于 2012-6-15 20:51 | 显示全部楼层
交作业 了!好象不太难。

第3讲-A03-ldxhzy.zip

22.08 KB, 下载次数: 10

点评

第一题目测已知区域,两个字典对比;第二题一个循环。  发表于 2012-6-20 13:13

评分

参与人数 1 +9 收起 理由
liuguansky + 9

查看全部评分

回复

使用道具 举报

发表于 2012-6-16 12:10 | 显示全部楼层
本帖最后由 wangfengren 于 2012-6-16 12:25 编辑

Sub t1()
    Dim d As New Dictionary
    Dim i As Integer
    For i = 2 To 9
        d(Cells(i, "E").Value) = d.Count + 1
    Next i
    For i = 2 To Range("a35536").End(xlUp).Row
    If d.Exists(Cells(i, 1).Value) = False Then
        d(Cells(i, 1).Value) = d.Count + 1
         Cells(d(Cells(i, 1).Value) + 1, "d").Value = d(Cells(i, 1).Value)
        Cells(d(Cells(i, 1).Value) + 1, "d").Font.Bold = True
        Cells(d(Cells(i, 1).Value) + 1, "E").Value = Cells(i, 1).Value
        Cells(d(Cells(i, 1).Value) + 1, "E").Font.Bold = True
        Cells(d(Cells(i, 1).Value) + 1, "F").Font.Bold = True
     End If
        Cells(d(Cells(i, 1).Value) + 1, "F").Value = Cells(d(Cells(i, 1).Value) + 1, "F").Value + Cells(i, 2).Value
    Next i
   
End Sub

Sub t2()
Dim d As New Dictionary
Dim arr(1 To 110, 1 To 2)
Dim i As Integer
For i = 1 To 110
    arr(i, 1) = Cells(i + 1, 1).Value
    arr(i, 2) = Cells(i + 1, 2).Value
    If IsEmpty(arr(i, 1)) Then
        arr(i, 1) = arr(i - 1, 1)
    End If
    d(arr(i, 1)) = arr(i, 2)
    If d(arr(i, 1)) >= 100 And d(arr(i, 1)) <= 400 Then
        d(arr(i, 1)) = d(arr(i, 1)) + arr(i, 2)
    End If
Next i
Range("e2").Resize(d.Count, 1) = Application.WorksheetFunction.Transpose(d.Keys)
Range("F2").Resize(d.Count, 1) = Application.WorksheetFunction.Transpose(d.Items)
End Sub

第三讲-A06-wangfengren.rar

14.12 KB, 下载次数: 7

点评

代码请以代码框贴出,  发表于 2012-6-20 13:14

评分

参与人数 1 +9 收起 理由
liuguansky + 9

查看全部评分

回复

使用道具 举报

发表于 2012-6-16 15:48 | 显示全部楼层
本帖最后由 byhdch 于 2012-6-16 15:52 编辑


  1. Sub 第一题汇总()
  2.     Dim i As Long
  3.     Dim d As New Dictionary
  4.     Dim arr, arr1(1 To 10000, 1 To 3), arr2
  5.     arr = Array("吉林省", "湖北省", "辽宁省", "海南省", "湖南省", "江西省", "四川省", "广西省")
  6.     For i = 0 To UBound(arr)
  7.         d(arr(i)) = d.Count + 1
  8.         arr1(d.Count, 2) = arr(i)
  9.         arr1(d.Count, 1) = d.Count
  10.     Next i
  11.     arr2 = Range("a2:b" & Range("b65536").End(xlUp).Row)
  12.     For i = 1 To UBound(arr2)
  13.         If d.Exists(arr2(i, 1)) = False Then
  14.             d(arr2(i, 1)) = d.Count + 1
  15.             arr1(d.Count, 2) = arr2(i, 1)
  16.             arr1(d.Count, 3) = arr2(i, 2)
  17.             arr1(d.Count, 1) = d.Count
  18.         Else
  19.             arr1(d(arr2(i, 1)), 3) = arr1(d(arr2(i, 1)), 3) + arr2(i, 2)
  20.         End If
  21.     Next i
  22.     Range("D2:F100").ClearContents
  23.     Range("D2").Resize(d.Count, UBound(arr1, 2)) = arr1
  24.     Range("D2:F100").Font.Bold = False
  25.     For i = 2 To Range("D65536").End(xlUp).Row
  26.         If Range("D" & i) > UBound(arr) + 1 Then Range("D" & i & ":F" & i).Font.Bold = True
  27.     Next i
  28.     Set d = Nothing
  29. End Sub

  30. Sub 第二题汇总()
  31.     Dim i As Long
  32.     Dim d As New Dictionary
  33.     Dim arr, arr1(1 To 10000, 1 To 2)
  34.     arr = Range("a2:b" & Range("b65536").End(xlUp).Row)
  35.     For i = 1 To UBound(arr)
  36.         If arr(i, 1) = "" Then arr(i, 1) = arr(i - 1, 1)
  37.         If d.Exists(arr(i, 1)) = False And arr(i, 2) >= [C2] And arr(i, 2) <= [D2] Then
  38.             d(arr(i, 1)) = d.Count + 1
  39.             arr1(d.Count, 1) = arr(i, 1)
  40.             arr1(d.Count, 2) = arr(i, 2)
  41.         ElseIf d.Exists(arr(i, 1)) = True And arr(i, 2) >= [C2] And arr(i, 2) <= [D2] Then
  42.             arr1(d(arr(i, 1)), 2) = arr1(d(arr(i, 1)), 2) + arr(i, 2)
  43.         End If
  44.     Next i
  45.     Range("E2:F100").ClearContents
  46.     Range("E2").Resize(d.Count, 2) = arr1
  47.     Set d = Nothing
  48. End Sub

复制代码
第3讲-A20-byhdch.rar (16.28 KB, 下载次数: 8)

评分

参与人数 1 +10 收起 理由
liuguansky + 10

查看全部评分

回复

使用道具 举报

发表于 2012-6-17 00:25 | 显示全部楼层
第2讲-A04-tt253605057
  1. Sub a()    '题1
  2.     Dim arr, brr, i%, j%, d As Object
  3.     Sheets("题1").Activate
  4.     Range("d10:f" & [d65536].End(3).Row + 1).ClearContents
  5.     arr = Range("a1").CurrentRegion
  6.     brr = [D1:F9]
  7.     Set d = CreateObject("scripting.dictionary")
  8.     For i = 2 To UBound(arr)
  9.         d(arr(i, 1)) = arr(i, 2) + d(arr(i, 1))
  10.     Next i
  11.     For j = 2 To UBound(brr)
  12.         brr(j, 3) = d(brr(j, 2))
  13.         d.Remove (brr(j, 2))
  14.     Next j
  15.     Range("D1").Resize(UBound(brr), 3) = brr
  16.     If d.Count = 0 Then
  17.         Exit Sub
  18.     Else:
  19.         [D10].Resize(d.Count, 1) = Evaluate(Range("D2:D" & d.Count + 1).Address & "+" & 8)
  20.         [E10].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
  21.         [D10].Resize(d.Count, 2).Font.Bold = True
  22.     End If
  23. End Sub
  24. Sub b() '题2
  25.     Dim a, b, d As Object, arr, i%
  26.     Sheets("题2").Activate
  27.     a = [d2]: b = [C2]
  28.     Set d = CreateObject("scripting.dictionary")
  29.     arr = Range("a1").CurrentRegion
  30.     For i = 2 To UBound(arr)
  31.         If arr(i, 1) = "" Then arr(i, 1) = arr(i - 1, 1)
  32.         d(arr(i, 1)) = d(arr(i, 1)) + arr(i, 2) * (arr(i, 2) > b) * (arr(i, 2) < a)
  33.     Next i
  34.     [E2].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
  35. End Sub
复制代码

评分

参与人数 1 +11 收起 理由
liuguansky + 11 有部分函数思想,总的不错。

查看全部评分

回复

使用道具 举报

发表于 2012-6-17 03:32 | 显示全部楼层
因为涉及事件程序,所以没有附代码了

第3讲-A01-xdwy81129.rar (17.8 KB, 下载次数: 18)

点评

4+5待评分[]  发表于 2012-6-21 08:49
第一题单元格单个加BOLD,也没有屏幕刷新关闭,效率太差了,会卡卡的。第二题循环判断的合并单元格,不错  发表于 2012-6-21 08:48

评分

参与人数 1 +9 收起 理由
liuguansky + 9

查看全部评分

回复

使用道具 举报

发表于 2012-6-17 09:57 | 显示全部楼层
提交第三讲作业
第1题
Sub t()
Sheet1.Activate
Application.ScreenUpdating = False
Range("f2:f" & [f65536].End(xlUp).Row).ClearContents
    Dim d As New Dictionary
    Dim i As Byte
        For i = 2 To 9
            d(Cells(i, "e").Value) = i
        Next i
        For i = 2 To [a65536].End(xlUp).Row
            If d.Exists(Cells(i, 1).Value) = False Then
                d(Cells(i, 1).Value) = d.Count + 1
                Cells(d.Count + 1, "d") = d.Count
                Cells(d.Count + 1, "d").Font.Bold = True
                Cells(d.Count + 1, "e") = Cells(i, 1)
                Cells(d.Count + 1, "e").Font.Bold = True
                Cells(d.Count + 1, "f") = Cells(i, 2)
             Else
                Cells(d(Cells(i, 1).Value), "f") = Cells(d(Cells(i, 1).Value), "f") + Cells(i, 2)
            End If
        Next i
Application.ScreenUpdating = True
End Sub

第2题
Sub t2()
Sheet2.Select
Application.ScreenUpdating = False
Range("e2:f" & [f65536].End(xlUp).Row).ClearContents
    Dim d As New Dictionary
    Dim i As Byte
        For i = 2 To 111
            If Cells(i, 1) <> "" Then
                If d.Exists(Cells(i, 1).Value) = False Then
                    d(Cells(i, 1).Value) = d.Count + 2
                    Cells(d.Count + 1, "e") = Cells(i, 1)
                End If
            End If
        Next i
        For i = 2 To 111
            If Cells(i, 1) <> "" And Cells(i, 2) >= Range("c2") And Cells(i, 2) <= Range("d2") Then
                Cells(d(Cells(i, 1).Value), "f") = Cells(d(Cells(i, 1).Value), "f") + Cells(i, 2)
            Else
                If Cells(i, 1) = "" And Cells(i, 2) >= Range("c2") And Cells(i, 2) <= Range("d2") Then
                    Cells(d(Cells(i, 1).End(xlUp).Value), "f") = Cells(d(Cells(i, 1).End(xlUp).Value), "f") + Cells(i, 2)
                End If
            End If
        Next i
Application.ScreenUpdating = True
End Sub

点评

4+4待评  发表于 2012-6-21 08:50
题一,目测BOLD位置,单元格BOLD;题二,两次循环,单元格操作  发表于 2012-6-21 08:50

评分

参与人数 1 +8 收起 理由
liuguansky + 8

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-4 03:36 , Processed in 0.643639 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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