2017-12-20 8 views
1

以下は、私が現在一部の請求書タブで使用しているマクロです。ブックの最初のシートは、ハイパーリンクのワークシート名を使用してインデックスを作成するように設定されています。このモジュールはcrtl + shift + nによってアクティブになるように設定されていました。 2番目のサブは私がそれを試した最初のカップルを働いたが、今は、最初の空の行がいっぱいに満たされた前の行からデータをコピーしていません。それは最初のサブの後に停止するようです。何か案は?マクロfor excel VBAは同じモジュール内で2番目のサブを実行しません

Option Explicit 

Sub NewRequistionRecord() 
' 
' NewRequistionRecord Macro 
' Used for creaing a new requistion record to be auto updated in master 
Requisitions worksheet 
' 
' Keyboard Shortcut: Ctrl+Shift+N 
' 

Dim wb As Workbook: Set wb = ThisWorkbook 
Dim ws As Worksheet: Set ws = wb.sheets("BlankReq") 
Dim wbBefore As Workbook: Set wbBefore = Application.Workbooks("OPP Stores 
Orders Macro.xlsm") 
Dim wsBefore As Worksheet: Set wsBefore = wbBefore.sheets("BlankReq") 
Dim answer 
Dim NewName As String 
Application.ScreenUpdating = False 

    ws.Select 'Goes to template worksheet 


    ws.Copy Before:=wsBefore ' Forces a copy to be made always before the template so it is always at the end  
sheets("BlankReq (2)").Select 
sheets("BlankReq (2)").Name = "Enter Req Number" ' changes the name to indicate a requisition number needs to be entered 
Range("A1").Select ' hyperlink goes back Master Req index page 
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True 

Application.ScreenUpdating = True 

sheets("Enter Req Number").Select 
answer = MsgBox("Please rename the sheet with the Requisition number", vbOK) 

    If answer = vbOK Then 

Another: 
    NewName = InputBox("Requisition number - ?") 
    ActiveSheet.Name = NewName 

    Range("D2").Select 
    NewName = InputBox("Requisition Description- NO SPACES!! USE UNDERSCORE ?") 
    Range("D2").Value = NewName 
    wsBefore.Select 

    Range("H2").Select 
    NewName = InputBox("Please enter Requested By ") 
    Range("H2").Value = NewName 
    wsBefore.Select 
    answer = MsgBox("Please select your data to copy and paste into this sheet. Line Cost must be selected seperately from the items.", vbOKOnly) 

    End If 

End Sub 


Sub Filldown() 
Dim strFormulas(1 To 6) As Variant 
Dim wb As Workbook: Set wb = ThisWorkbook 
Dim ws As Worksheet: Set ws = wb.ActiveSheet 
Dim wbBefore As Workbook: Set wbBefore = Application.Workbooks("OPP StoresOrders Macro.xlsm") 
Dim wsBefore As Worksheet: Set wsBefore = wbBefore.sheets("BlankReq") 
Dim LRow As Long 
Dim xRow As Variant 
Application.ScreenUpdating = False 

     With ThisWorkbook.sheets("Requisitions") 
     Range("A1").Select 
     Columns("B:K").Select 
     Selection.SpecialCells(xlCellTypeBlanks).Select 
     Selection.FormulaR1C1 = "=R[-1]C" 
     End With 




Application.ScreenUpdating = True 

End Sub 

答えて

1

ショートカットはおそらくモジュールではなくサブに設定されています。したがって、2番目のサブはおそらくデフォルトでは実行されていません。

、まず、第1のサブを実行した後、第2のサブ、次のことを試してみる:

Sub TestMe() 
    NewRequistionRecord 
    FillDown 
End Sub 
+1

ありがとう私はそれをチェックアウトしてお知らせします – mrautomation

0

あなたは、すべての第2のマクロを呼び出していません。したがって、コードを実行し、2番目のマクロを実行するメッセージが表示されません。あなたは何とか2番目のマクロを実行するためにあなたのプログラムを伝える必要があります - 私は好きです call Macroname

+0

提案していただきありがとうございます。私はまだこれでかなり新しいです。 – mrautomation

+0

ねえ、私達はどこかで始まります!スプレッドシートのようなモジュールを考えてみましょう。モジュール内の各サブは別々のマクロです。個々のマクロごとにショートカット/ボタンを作成することができます。一度に複数のマクロを使用したい場合は、Sub Wrapper()のようにそれらをすべて保持するラッパーマクロが必要です。Macro1を呼び出してください。Macro2を呼び出してください。end sub – Selkie

+0

'Call'ステートメントは非推奨であるため、使用しないでくださいもう代わりに 'Macroname'(コールなし)と書いてください。 –

関連する問題