Excel VBA: 按照条件插入行



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


   




你可能感兴趣的:(VB)