Excel VBA: 按照条件插入行

来源:互联网 发布:宝宝店软件 编辑:程序博客网 时间:2024/05/16 19:48



Sub Macro1()

    Dim softwareVersion As String
    Dim recentFlag      As String
    Dim historyFlag     As String
    Dim maxRowsNumber   As Long
    Dim targetColumn    As Integer
    Dim imageColumn     As Integer
   
    maxRowsNumber = 65535
    recentFlag = "Y"
    historyFlag = "N"
    targetColumn = 8
    imageColumn = 10
   
    'Enter the newest version in this place
    softwareVersion = "3.08.00"

    For i = 7 To maxRowsNumber Step 1
   
       If Cells(i, 6) = recentFlag Then
            Rows(i).Copy
           
            Rows(i + 1).Insert
            Cells(i, 6) = historyFlag
           
            Cells(i + 1, 6) = recentFlag
            Cells(i + 1, 8) = softwareVersion
            Cells(i + 1, 10) = softwareVersion
           
            i = i + 1
        ElseIf Cells(i, 6) = "" Then
       
            i = maxRowsNumber
           
        End If
       
    Next i
   
End Sub


Sub Macro1()

    Dim SoftwareVersion As String
    SoftwareVersion = "3.08.00"

    For i = 7 To 65535 Step 1
   
       If Cells(i, 6) = "Y" Then
            Rows(i).Copy
           
            Rows(i + 1).Insert
            Cells(i, 6) = "N"
           
            Cells(i + 1, 6) = "Y"
            Cells(i + 1, 8) = SoftwareVersion
            Cells(i + 1, 10) = SoftwareVersion
           
            i = i + 1
        ElseIf Cells(i, 6) = "" Then
            i = 65535
        End If
       
    Next i
   
End Sub


   



0 0
原创粉丝点击