您的位置:首页 > 编程语言 > VB

Excel VBA: 按照条件插入行

2014-05-30 15:34 274 查看
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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: