Code Snippet

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
'填充序号
'@Author: kmlxk#yahoo.com.cn
'@Date: 2012-05-10
'@Desc: Excel的填充功能比较智能, 但是在合并过的单元格上填充时要求大小一致。这段代码模拟手工方式输入序号,避开了填充时的各种要求。简单粗暴的填充方式可能有点慢,慎用于上千行的序号填充。
'
Sub 在列上模拟手工填充序号()
    Dim strStartCell As String
    Dim i As Long
    Dim iStart As Long
    Dim iEnd As Long
    
    ' 初始化变量
    
    ' 起始单元格
    strStartCell = "A2"
    ' 起始序号
    iStart = 1
    ' 终止序号
    iEnd = 10
    
    ' 选择起始单元格
    Range(strStartCell).Select
    ' 填写序号
    ActiveCell.FormulaR1C1 = Str(iStart)
    
    
    For i = iStart + 1 To iEnd
        '按键下
        Application.SendKeys "{DOWN}"
        '输入序号
        Application.SendKeys Str(i)
    Next

End Sub

 

posted on 2012-05-10 11:30  kmlxk  阅读(580)  评论(0编辑  收藏  举报