返回列表 上一主題 發帖

[發問] 按鈕無法指定巨集問題

[發問] 按鈕無法指定巨集問題

程式編寫完後,設定按鈕,指定巨集,指定巨集時,
會出現 "參照來源必須是巨集表" 的錯誤訊息
不知是設定上有問題 ? 還是程式碼有問題 ?
請教高手大大要如何解決! 謝謝感恩

程式碼如下
Dim x

Sub b1()
'
' b1 b
'每月資料整理程序
      
        x = InputBox("年月") '欄位名稱
        
        If Mid(x, 4, 1) = 1 Then
           x1 = Mid(x, 4, 2)
        Else
           x1 = Mid(x, 5, 1)
        End If
        
                    x2 = x1
                    x1 = x1 & "月"
                    x2 = x2 & "月排名"
    Call b11
    Sheets(x1).Select
    Call b12
    Sheets(x2).Select
    Call b12
    MsgBox "新增完成"
End Sub
Sub b11()
        'yoy分析資料整理
        Application.ScreenUpdating = False '停止螢幕更新以加快速度
        Sheets("yoy分析").Select
        'x = InputBox("年月") '首欄名稱
        y = Cells(1, 1).End(xlToRight).Column '找最後一欄資料
        Z = Cells(1, y).End(xlDown).Row '找最後一列資料
        Cells(1, y + 1) = x
        Range(Cells(2, y), Cells(Z, y)).Copy Range(Cells(2, y + 1), Cells(Z, y + 1))
        Range(Cells(2, y), Cells(Z, y)).Copy
        Cells(2, y).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False '選擇性貼上值
        
End Sub
Sub b12()
        '月排名資料整理
        
        
        'x = InputBox("年月") '首欄名稱
        y = Cells(1, 1).End(xlToRight).Column '找最後一欄資料
        Z = Cells(1, y).End(xlDown).Row '找最後一列資料
        Cells(1, y + 1) = x
        Range(Cells(2, y), Cells(Z, y)).Copy Range(Cells(2, y + 1), Cells(Z, y + 1))
        Range(Cells(2, y), Cells(Z, y)).Copy
        Cells(2, y).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False '選擇性貼上值
        
End Sub

原來是這樣!
感謝K大解答

TOP

謝謝K大G大幫忙
名稱更改後就沒問題了

TOP

        靜思自在 : 願要大、志要堅、氣要柔、心要細。
返回列表 上一主題