excel VBA的宏不会在同一模块中运行第二个子

时间:2017-12-20 14:40:36

标签: excel excel-vba indexing hyperlink autofill vba

以下是我目前用于某些发票标签的宏。工作簿中的第一个工作表设置为使用超链接的工作表名称进行索引。该模块设置为由crtl + shift + n激活。第二个子工作了前几次我尝试了但是现在它没有复制上一行中的数据填充到第一个空行填充。似乎它在第一个潜艇后停止了。有什么想法吗?

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 

2 个答案:

答案 0 :(得分:1)

快捷方式可能设置为Sub,而不是模块。因此,默认情况下,第二个子可能没有运行。

要先运行第一个sub,然后运行第二个sub,请尝试以下操作:

Sub TestMe()
    NewRequistionRecord
    FillDown
End Sub

答案 1 :(得分:0)

你根本没有调用第二个宏。所以它贯穿代码,并且它没有得到消息来运行第二个宏。你需要以某种方式告诉你的程序运行第二个宏 - 我喜欢  call Macroname