三九宝宝网宝宝绘画儿童画

EXCEL VBA宏语言排序问题附有图片

12月30日 编辑 39baobao.com

问题1

Private Sub CommandButton1_Click()

Dim i, j As Long

Sheets("sheet2").Cells.ClearContents

Sheets("sheet1").Cells.Copy

Sheets("sheet2").Select

Sheets("sheet2").Range("A1").Select

ActiveSheet.Paste

i = 3

Do While Sheets("sheet2").Range("A" & i).Value <> ""

For j = 2 To i - 1

If Sheets("sheet2").Range("A" & i).Value > Sheets("sheet2").Range("A" & j).Value Then

Else

Sheets("sheet2").Rows(i & ":" & i).Cut

Sheets("sheet2").Rows(j & ":" & j).Insert Shift:=xlDown

Exit For

End If

Next j

i = i + 1

Loop

End Sub

问题2

Private Sub CommandButton1_Click()

Dim i, j As Long

Sheets("sheet2").Cells.ClearContents

Sheets("sheet1").Cells.Copy

Sheets("sheet2").Select

Sheets("sheet2").Range("A1").Select

ActiveSheet.Paste

i = 3

Do While Sheets("sheet2").Range("A" & i).Value <> ""

For j = 2 To i - 1

If Sheets("sheet2").Range("C" & i).Value & Sheets("sheet2").Range("D" & i).Value > Sheets("sheet2").Range("C" & j).Value & Sheets("sheet2").Range("D" & j).Value Then

Else

Sheets("sheet2").Rows(i & ":" & i).Cut

Sheets("sheet2").Rows(j & ":" & j).Insert Shift:=xlDown

Exit For

End If

Next j

i = i + 1

Loop

End Sub

推荐阅读
图文推荐