码迷,mamicode.com
首页 > 其他好文 > 详细

整理BOM时写的关于拆分单元格的VB代码

时间:2015-09-30 17:48:06      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

Public Function AddRows(pos As Integer, amount As Integer)
    Dim rpos As Integer
    rpos = pos + 1
    For i = 1 To amount
        ActiveSheet.Rows(rpos).Insert
    Next i
End Function
Public Function PasteRows(startPos As Integer, amount As Integer)
    Dim rStartPos As Integer
    Dim rEndPos As Integer
    Dim startPosStr As String
    Dim endPosStr As String
    
    startPosStr = str(startPos)
    rStartPos = startPos + 1
    rEndPos = startPos + amount
    
    Rows(startPos & ":" & startPos).Select
    Selection.Copy
    Rows(startPos + 1 & ":" & rEndPos).Select
    ActiveSheet.Paste
End Function
Public Function ElementNum(str As String) As Integer
    Dim a() As String
    a = Split(str, ",")
    ElementNum = UBound(a) - LBound(a)
End Function
Public Function PasteCells(str As String, pos As Integer)
    Dim a() As String
    Dim num As Integer
    Dim i As Integer
    Dim j As Integer
    
    j = 0
    a = Split(str, ",")
    num = UBound(a) - LBound(a) + pos
    For i = pos To num
        ActiveSheet.Cells(i, 2) = a(j)
        j = j + 1
    Next i
End Function

Sub BomSplit()
    Dim rowNum As Integer
    Dim i As Integer
    Dim j As Integer
    
    j = 1
    For i = 1 To 3
        rowNum = ElementNum(ActiveSheet.Cells(j, 2))
        If rowNum > 0 Then
            Call AddRows(j, rowNum)
            Call PasteRows(j, rowNum)
            Call PasteCells(ActiveSheet.Cells(j, 2), j)
        End If
        j = j + rowNum + 1
    Next i
End Sub

 

整理BOM时写的关于拆分单元格的VB代码

标签:

原文地址:http://www.cnblogs.com/cnpirate/p/4849582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!