Stack Tre Macro in un Comando VBA

Ho tre macro (in basso) che funzionano separatamente, ma quando le ho messe insieme, solo la prima macro esegue correttamente. Non sto ottenendo un errore; le altre due macro non sembrano correre. Qualunque consiglio su come collegarli insieme in modo da poter eseguire tutto in una volta?


Macro 1

  • Excel "Do While" Loop Non funziona correttamente dopo la prima iterazione
  • Laravel Excel, esportndo da un model, problemi di styling
  • Errore durante la copia di più di 8202 caratteri da una cella all'altra
  • Eliminazione di colonne inserite con un'unione
  • Tabella pivot excel o R
  • Problema di formattazione di esportzione SSRS
  • Sub Update_Workbook() Dim QryStr As String, cell As String Dim a As Integer, b As Integer Dim cellv As Variant 'Pause spreadsheet calculations until end of sub Application.Calculation = xlManual ActiveWorkbook.Sheets("Raw Data").Select 'Clear cells to import query With Range("A1:O1").EntireColumn .ClearContents .NumberFormat = "General" .Validation.Delete End With 'Process SQL query string QryStr = ActiveSheet.TextBox1.Value Do While InStr(QryStr, "{&") a = InStr(QryStr, "{&") b = InStr(a, QryStr, "}") cell = Mid(QryStr, a + 2, b - a - 2) cellv = Range(cell).Value If IsDate(cellv) Then cellv = Format(cellv, "dd-mmm-yy") End If QryStr = Replace(QryStr, "{&" & cell & "}", cellv) Loop 'Import data from query With ActiveSheet.QueryTables.Add(Connection:="ODBC;DRIVER={Oracle in OraClient11g_home1};UID=xx;PWD=xx;SERVER=xx;DBQ=xx", _ Destination:=Range("A1"), Sql:=QryStr) .MaintainConnection = False .BackgroundQuery = False .RefreshStyle = xlOverwriteCells .Refresh .Delete End With Finish_Sub: Call ClearUnneededNames Application.Calculation = xlCalculationAutomatic End Sub Sub ClearUnneededNames() Dim savedNames As Integer savedNames = 0 Do While ActiveSheet.Names.Count > savedNames If InStr(ActiveSheet.Names(savedNames + 1).Name, "ExternalData") = 0 Then savedNames = savedNames + 1 Else ActiveSheet.Names(savedNames + 1).Delete End If Loop End Sub 

    Macro 2

     Sub Five_Felicia_for_MFG() ' ' Macro3 Macro ' ' Range("A3:M3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlDown)).Select ActiveWindow.SmallScroll Down:=-18 Range(Selection, Selection.End(xlUp)).Select Range("A3:M1010").Select Selection.Delete Shift:=xlUp Sheets("5Felicia").Select Range("A3:M34").Select Selection.Copy Sheets("5Felicia for MFG").Select Range("A3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets("5Felicia").Select Range("A37:M37").Select Range(Selection, Selection.End(xlDown)).Select Range("A37:M692").Select Application.CutCopyMode = False Selection.Copy Sheets("5Felicia for MFG").Select ActiveWindow.SmallScroll Down:=18 Range("A36").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveWindow.SmallScroll Down:=-48 Columns("A:M").Select Application.CutCopyMode = False ActiveSheet.Range("$A$1:$M$691").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _ 7, 8, 9, 10, 11, 12, 13), Header:=xlNo End Sub Range (Selezione, Selezione.End (xlUp)). Selezionare Sub Five_Felicia_for_MFG() ' ' Macro3 Macro ' ' Range("A3:M3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlDown)).Select ActiveWindow.SmallScroll Down:=-18 Range(Selection, Selection.End(xlUp)).Select Range("A3:M1010").Select Selection.Delete Shift:=xlUp Sheets("5Felicia").Select Range("A3:M34").Select Selection.Copy Sheets("5Felicia for MFG").Select Range("A3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets("5Felicia").Select Range("A37:M37").Select Range(Selection, Selection.End(xlDown)).Select Range("A37:M692").Select Application.CutCopyMode = False Selection.Copy Sheets("5Felicia for MFG").Select ActiveWindow.SmallScroll Down:=18 Range("A36").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveWindow.SmallScroll Down:=-48 Columns("A:M").Select Application.CutCopyMode = False ActiveSheet.Range("$A$1:$M$691").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _ 7, 8, 9, 10, 11, 12, 13), Header:=xlNo End Sub Range (Selezione, Selezione.End (xlUp)). Selezionare Sub Five_Felicia_for_MFG() ' ' Macro3 Macro ' ' Range("A3:M3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlDown)).Select ActiveWindow.SmallScroll Down:=-18 Range(Selection, Selection.End(xlUp)).Select Range("A3:M1010").Select Selection.Delete Shift:=xlUp Sheets("5Felicia").Select Range("A3:M34").Select Selection.Copy Sheets("5Felicia for MFG").Select Range("A3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets("5Felicia").Select Range("A37:M37").Select Range(Selection, Selection.End(xlDown)).Select Range("A37:M692").Select Application.CutCopyMode = False Selection.Copy Sheets("5Felicia for MFG").Select ActiveWindow.SmallScroll Down:=18 Range("A36").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveWindow.SmallScroll Down:=-48 Columns("A:M").Select Application.CutCopyMode = False ActiveSheet.Range("$A$1:$M$691").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _ 7, 8, 9, 10, 11, 12, 13), Header:=xlNo End Sub Selection.PasteSpecial Paste: = xlPasteFormats, Funzionamento: = xlNone, _ Sub Five_Felicia_for_MFG() ' ' Macro3 Macro ' ' Range("A3:M3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlDown)).Select ActiveWindow.SmallScroll Down:=-18 Range(Selection, Selection.End(xlUp)).Select Range("A3:M1010").Select Selection.Delete Shift:=xlUp Sheets("5Felicia").Select Range("A3:M34").Select Selection.Copy Sheets("5Felicia for MFG").Select Range("A3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets("5Felicia").Select Range("A37:M37").Select Range(Selection, Selection.End(xlDown)).Select Range("A37:M692").Select Application.CutCopyMode = False Selection.Copy Sheets("5Felicia for MFG").Select ActiveWindow.SmallScroll Down:=18 Range("A36").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveWindow.SmallScroll Down:=-48 Columns("A:M").Select Application.CutCopyMode = False ActiveSheet.Range("$A$1:$M$691").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _ 7, 8, 9, 10, 11, 12, 13), Header:=xlNo End Sub Selection.PasteSpecial Paste: = xlPasteFormats, Funzionamento: = xlNone, _ Sub Five_Felicia_for_MFG() ' ' Macro3 Macro ' ' Range("A3:M3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlDown)).Select ActiveWindow.SmallScroll Down:=-18 Range(Selection, Selection.End(xlUp)).Select Range("A3:M1010").Select Selection.Delete Shift:=xlUp Sheets("5Felicia").Select Range("A3:M34").Select Selection.Copy Sheets("5Felicia for MFG").Select Range("A3").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets("5Felicia").Select Range("A37:M37").Select Range(Selection, Selection.End(xlDown)).Select Range("A37:M692").Select Application.CutCopyMode = False Selection.Copy Sheets("5Felicia for MFG").Select ActiveWindow.SmallScroll Down:=18 Range("A36").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveWindow.SmallScroll Down:=-48 Columns("A:M").Select Application.CutCopyMode = False ActiveSheet.Range("$A$1:$M$691").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _ 7, 8, 9, 10, 11, 12, 13), Header:=xlNo End Sub 

    Macro 3

     Sub DUMMY_ITEMS() ' ' DUMMY_ITEMS Macro Dim LastRow As Long Sheets("Operations").Range("H2:V73").Copy With Sheets("Raw Data") LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row .Range("A" & LastRow + 1).PasteSpecial xlPasteValues End With End Sub 

  • Office Interop apre il file xlsx in un client con Excel 2003
  • Rails: aggiungere il bordo in axlsx
  • Formattazione condizionale basata sul valore in Excel
  • Scrivere il valore della cella da una colonna a una posizione specificata da altre celle
  • SHAPE, inserito nella cella, ostacola la selezione delle cellule
  • Come simulare l'attributo onAction tab?
  • One Solution collect form web for “Stack Tre Macro in un Comando VBA”

    In VBA un module può avere diverse macro (o, più precisamente, sottoprogrammi) in esso.

    Tuttavia, quando si chiama una di queste macro, l'esecuzione si arresta all'istruzione End Sub . Nient'altro nel module verrà eseguito indipendentemente dal modo in cui li "panini" insieme nel module.

    Ma le subroutine possono call altre sottoprogrammi. Quindi codice come questo eseguirà tutte e tre le tue macros:

     Sub RunAllThree() Update_Workbook Five_Felicia_for_MFG DUMMY_ITEMS End Sub 
    Microsoft Office Excel Spreadsheet è il miglior software di Office, Excel VBA e formule Excel rendono il foglio di calcolo più veloce.