- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2012-9-21 16:13
| 只看該作者
回復 1# Genie
選第二列 的邏輯看不懂
選第一列 如下- Sub 插入欄()
- Dim i As Integer, r As String, Rng As Range, E As Range
- Dim iRow As Integer
- If iRow > 3 Then Exit Sub '此程式碼沒作用?? : iRow 程式中你尚未給值
- Application.ScreenUpdating = False
- Do
- r = InputBox("輸入插入欄數,必須 >= 1 ", "插入欄數", "1")
- Loop Until r <> "" And r >= 1
- For i = 2 To [A2].End(xlToRight).Column - 1
- If Cells(1, i) <> Cells(1, i + 1) Then
- If Rng Is Nothing Then Set Rng = Cells(1, i) Else Set Rng = Union(Cells(1, i), Rng)
- End If
- Next
- If Not Rng Is Nothing Then
- For Each E In Rng.Cells
- E.Offset(, 1).Resize(, r).EntireColumn.Insert
- Next
- End If
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|