分类：电脑/网络-软件
问题：excel代码老师您好；选择了一部分数据上传给您。注意事项在表1 
您好；   选择了一部分数据上传给您。注意事项在表1里。希望得到您的帮助！
回答：修改后宏：运行下就可以了至于排序，宏里包含了，自己想排序的化可以 在单数据-排序里自己设置如果想自己排序就把下面那分号下的一段代码删除，手动排序就好。Sub Macro1()'' Macro1 Macro''Sheets("Sheet3").Cells(1, 1) = "年度"Sheets("Sheet3").Cells(1, 2) = "月份"Sheets("Sheet3").Cells(1, 3) = "凭证号"Sheets("Sheet3").Cells(1, 4) = "摘要"Sheets("Sheet3").Cells(1, 5) = "总账科目"Sheets("Sheet3").Cells(1, 6) = "明细科目"Sheets("Sheet3").Cells(1, 7) = "借方金额"Sheets("Sheet3").Cells(1, 8) = "贷方金额"ai = 3aai = 3Do While Sheets("表1").Cells(aai, 1) <> ""    If Sheets("表1").Cells(ai, 5) <> "" Then        Sheets("Sheet3").Cells(ai - 1, 1) = Sheets("表1").Cells(aai, 1)        Sheets("Sheet3").Cells(ai - 1, 2) = Sheets("表1").Cells(aai, 2)        Sheets("Sheet3").Cells(ai - 1, 3) = Sheets("表1").Cells(aai, 3)        Sheets("Sheet3").Cells(ai - 1, 4) = Sheets("表1").Cells(aai, 4)        Sheets("Sheet3").Cells(ai - 1, 5) = Sheets("表1").Cells(aai, 5)        Sheets("Sheet3").Cells(ai - 1, 6) = Sheets("表1").Cells(aai, 6)        Sheets("Sheet3").Cells(ai - 1, 7) = Sheets("表1").Cells(aai, 9)        ai = ai + 1     End If    aai = aai + 1Loopbi = 3Do While Sheets("表1").Cells(bi, 1) <> ""    If Sheets("表1").Cells(bi, 7) <> "" Then        Sheets("Sheet3").Cells(ai - 1, 1) = Sheets("表1").Cells(bi, 1)        Sheets("Sheet3").Cells(ai - 1, 2) = Sheets("表1").Cells(bi, 2)        Sheets("Sheet3").Cells(ai - 1, 3) = Sheets("表1").Cells(bi, 3)        Sheets("Sheet3").Cells(ai - 1, 4) = Sheets("表1").Cells(bi, 4)        Sheets("Sheet3").Cells(ai - 1, 5) = Sheets("表1").Cells(bi, 7)        Sheets("Sheet3").Cells(ai - 1, 6) = Sheets("表1").Cells(bi, 8)        Sheets("Sheet3").Cells(ai - 1, 8) = Sheets("表1").Cells(bi, 9)        ai = ai + 1    End If        bi = bi + 1Loop   ' Range("A1:I10").Select   ' Selection.Copy   ' Sheets("Sheet3").Select   ' ActiveSheet.Paste       Range("A1:C1").Select    ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Clear    ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Add Key:=Range("A2:A185") _        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal    ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Add Key:=Range("B2:B185") _        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal    ActiveWorkbook.Worksheets("Sheet3").Sort.SortFields.Add Key:=Range("C2:C185") _        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal    With ActiveWorkbook.Worksheets("Sheet3").Sort        .SetRange Range("A1:H185")        .Header = xlYes        .MatchCase = False        .Orientation = xlTopToBottom        .SortMethod = xlPinYin        .Apply    End With    ActiveWindow.SmallScroll Down:=3   End Sub