加空行

Option Explicit
Public addnum_clo As String
Public businessname_clo As String
Public status_clo As String
Public supply_price_clo As String
Public shop_id_clo As String

Sub main()
    
    addnum_clo = "H"
    businessname_clo = "M"
    status_clo = "N"
    supply_price_clo = "K"
    shop_id_clo = "L"
    
    Call add_space(businessname_clo)
    
End Sub
Private Sub add_space(which_clo As String)
    Dim head_rng_content As Range
    Dim clo_num As Integer
    Dim row_num  As Long
    Dim cursor As Long
    
    Set head_rng_content = Range(Cells(1, 1), Cells(1, 1).End(xlToRight))
    clo_num = get_clo_num()
    row_num = get_row_num()
    
    For cursor = 2 To row_num * 2
        If Cells(cursor, which_clo) <> Cells(cursor - 1, which_clo) Then
            Rows(cursor).Resize(2).Insert
            cursor = cursor + 2
            head_rng_content.Copy Range(Cells(cursor - 1, 1), Cells(cursor - 1, clo_num))
        End If
    Next
    
    
End Sub

Private Function get_clo_num()
    Dim clo_num As Integer
    Dim clo_rng As Range
    
    Set clo_rng = Range(Cells(1, 1), Cells(1, 1).End(xlToRight))
    clo_num = Application.WorksheetFunction.CountA(clo_rng)
    get_clo_num = clo_num
End Function

Private Function get_row_num()
    Dim row_num As Long
    Dim row_rng As Range
    
    Set row_rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
    row_num = Application.WorksheetFunction.CountA(row_rng)
    get_row_num = row_num
End Function



你可能感兴趣的:(加空行)