返回列表 上一主題 發帖

每隔多少欄插入多少欄程式錯誤需幫忙

每隔多少欄插入多少欄程式錯誤需幫忙

有一個程式 是希望它能每隔多少欄插入多少欄
但有一個地方一直出現錯誤 (Mark 紅色處)
希望能夠幫我看一下 謝謝∼
程式如下:

Sub 插入欄()
   
    Dim BeginCol As Long, AA As Long, Temp As String, InsCol As Long
    Dim myRow As Integer, tempCol As Long
   
    myRow = Selection.Row
    BeginCol = Selection.Column
   
    Temp = InputBox("隔幾欄")
   
        If IsNumeric(Temp) Then AA = CLng(Temp) Else Exit Sub
   
    Temp = InputBox("插入幾欄")
            
        If IsNumeric(Temp) Then InsCol = CLng(Temp) Else Exit Sub
   
    Application.ScreenUpdating = False
   
    Do While True
        tempCol = Range(Cells(myRow, 255), Cells(myRow, 255)).End(xlToLeft).Column
        If tempCol < (BeginCol + AA) Then Exit Do
        BeginCol = BeginCol + AA
        Columns(BeginCol & ":" & BeginCol + InsRow - 1).Insert Shift:=xlToRight
        BeginCol = BeginCol + InsCol
    Loop
        
    Application.ScreenUpdating = True
   
End Sub

所以我該從一開始的定義就開始改是嗎?
還是可以把 Columns 用別的參數做取代呢?
謝謝∼

TOP

謝謝 luhpro 和 chin15 解決了我的問題
同時也學到了新的用法

非常感謝∼

TOP

        靜思自在 : 受人點水之恩,須當湧泉以報。
返回列表 上一主題