Dzwebs.Net

撰写电脑技术杂文十余年

Excel Vba根据班级号从总表自动填充班级学生到子表

Admin | 2017-3-7 9:23:20 | 被阅次数 | 8584

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  有一总表,保存的是年级的所有学生的信息。另外,有一子表,只显示当前班级的学生。

  现在,要做的就是,在子表里面,选择班级号,然后根据VBA自动从总表中找到本班的学生填充到子表。

  总表信息如下,都是学生的基本信息。


  子表如下,当我们选择一个班级后,再点击“填充数据”按钮,那么,将会自动根据班级号从总表中找到对应班级的信息填充到子表里面。


  其它不多说,功能代码如下:

  Dim Boot1
  Dim Boot2
    For i = 3 To 42 '清理原来数据
        Sheets("按班级打印").Cells(i, 2).Value = ""
        Sheets("按班级打印").Cells(i, 3).Value = ""
        Sheets("按班级打印").Cells(i, 4).Value = ""
        Sheets("按班级打印").Cells(i, 7).Value = ""
        Sheets("按班级打印").Cells(i, 8).Value = ""
        Sheets("按班级打印").Cells(i, 9).Value = ""
    Next i
    For i = 3 To Sheets("2019届学籍信息").UsedRange.Rows.Count
        If (Trim(Sheets("2019届学籍信息").Cells(i, 3).Value) = Trim(Sheets("按班级打印").Cells(3, 11).Value)) Then
            Boot1 = Boot1 + 1
            If (Boot1 <= 40) Then
              Sheets("按班级打印").Cells(Boot1 + 2, 2).Value = Sheets("2019届学籍信息").Cells(i, 1).Value '填充学籍号
              Sheets("按班级打印").Cells(Boot1 + 2, 3).Value = Sheets("2019届学籍信息").Cells(i, 2).Value '填充姓名
              Sheets("按班级打印").Cells(Boot1 + 2, 4).Value = Sheets("2019届学籍信息").Cells(i, 3).Value '填充班级
            Else
              Boot2 = Boot2 + 1
              Sheets("按班级打印").Cells(Boot2 + 2, 7).Value = Sheets("2019届学籍信息").Cells(i, 1).Value '填充学籍号
              Sheets("按班级打印").Cells(Boot2 + 2, 8).Value = Sheets("2019届学籍信息").Cells(i, 2).Value '填充姓名
              Sheets("按班级打印").Cells(Boot2 + 2, 9).Value = Sheets("2019届学籍信息").Cells(i, 3).Value '填充班级
            End If
        End If
    Next i
    Boot1 = 0
    Boot2 = 0

  说明:Sheets("2019届学籍信息")为总表。Sheets("按班级打印")为子表。


该杂文来自: Excel杂文

上一篇:MIRR返回某一连续期间内现金流的修正内部收益率

下一篇:Excel输入技巧

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计