→ newton41: For rN = endRow to startRow+1 step -1 05/19 00:02
→ newton41: If cells(rN,2)<>cells(rN-1,2) then rows(rN).inse 05/19 00:02
→ newton41: rt 05/19 00:02
→ newton41: Next 05/19 00:02
→ newton41: 大概類似這樣,從下面跑回去就比較不會被插入列影響到。 05/19 00:04
→ newton41: 你的檔案我沒看,可以的話貼到文章吧。 05/19 00:04
原程式碼如下,不知道改怎麼修改?
Dim IntCount As Integer
IntCount = Application.WorksheetFunction.CountA(Range("A:A")) - 1
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = "temp"
Range("A2").Select
ActiveCell.FormulaR1C1 = "1"
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Stop:=IntCount, Trend:=False
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("工作表1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("工作表1").Sort.SortFields.Add
Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("工作表1").Sort
.SetRange ActiveCell.Range("A2:N" & (IntCount * 2))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Delete Shift:=xlToLeft
ActiveCell.Select
※ 編輯: nash30113 (114.24.153.3), 05/19/2018 00:10:10
→ nash30113: 感謝S大,原來可以改成這麼簡潔!! 05/19 00:11
→ newton41: 聽s大的錯不了。 05/19 00:12
→ nash30113: n大也感謝你的協助! 05/19 00:14
→ soyoso: 如要以原巨集碼的邏輯的話 05/19 00:39
→ soyoso: 則保留 05/19 00:40
→ nash30113: 非常感謝S大的協助!! 05/19 12:13