|
楼主 |
发表于 2008-3-25 23:16:43
|
显示全部楼层
alt+F11
然后菜单,插入模块..
然后粘贴以下内容,最后按F5, 实现你需要的功能:- Sub insertNumber()
- Dim oldCol As Long, printCol As Long
- Dim rowI As Long, rowP As Long, sTmp As String
- Dim j As Long, lastN As Long, nextN As Long
- oldCol = 1 '原始列号
- printCol = 3 '需要打印的列号
- Do
- rowI = rowI + 1 '逐行读取
- sTmp = Cells(rowI, oldCol).Value
- Select Case sTmp
- Case Is = ""
- Exit Do '如果此行为空就退出
- Case Is = ".." '如果为.. 就补齐中间的数据
- If rowI <= 1 Then'如果首行为.. 就输出一个错误标记
- rowP = rowP + 1
- Cells(rowP, printCol).Value = "Error"
- Cells(rowP, printCol).Interior.Color = vbRed'并改变背景色为红色
- Else
- lastN = Val(Cells(rowI - 1, oldCol).Value)
- nextN = Val(Cells(rowI + 1, oldCol).Value)
- For j = lastN + 1 To nextN - 1 '循环补齐需要插入的内容
- rowP = rowP + 1
- Cells(rowP, printCol).Value = j
- Cells(rowP, printCol).Interior.Color = vbYellow '并改变背景色为黄色
- Next
- End If
- Case Else
- rowP = rowP + 1
- Cells(rowP, printCol).Value = sTmp '正常行输出
- End Select
- Loop
- End Sub
复制代码 :loveliness: |
|