Results 1 to 15 of 15

Thread: join models

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    Took a quick look

    I'd suggest making things more modular

    In my example, the Main sub calls the lower level subs and for clarity eacn lower level sub is on a separate sheet

    The user just needs to run "Main" and it calls the others

    Not sure about the rest you want to run, but look at this version

    After I deleted the code that is in the other modules, mod_50_More has the remainder


    Your main macro could look something like this

    Option Explicit
    
    
    Sub Main2()
    
        Dim wsData As Worksheet
        Dim bDoNegatives As Boolean
    
        'make sure we're on the right sheet
        If ActiveSheet.Name = "Data" Then
            Call MsgBox("Can't do it on the Data sheet. Pick another", vbCritical + vbOKOnly, "Format Macro")
            Exit Sub
        Else
            If MsgBox("Do you want to run the format macro on this sheet?", vbQuestion + vbYesNo, "Format Macro") = vbNo Then
                Exit Sub
            End If
        End If
        
        'see if we're going to do the negative numbers
        bDoNegatives = (MsgBox("Do you want to change the negative prices?", vbQuestion + vbYesNo, "Format Macro") = vbYes)
    
        'setup and init
        Application.ScreenUpdating = False
        ActiveSheet.Name = "Input"
        Set wsData = Worksheets("Data")
    
        Call ReplaceAllSheets(wsData.Range("A1"))
        Call ReplaceAllSheets(wsData.Range("D1"))
        Call ReplaceAllSheets(wsData.Range("G1"))
        
        Call addClassReturns
       
         If bDoNegatives Then Call Negative
        
        Call Template
        Call AddDiscountReturns
        Call More                       '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< the rest of the code mod_50
        
        'cleanup
        With Worksheets("Input")
            .Range("A1").Value = "Invoice Date"
            .Range("B1").Value = "Invoice Number"
            .Range("C1").Value = "Account Name"
            .Range("D1").Value = "Item"
            .Range("E1").Value = "Qty"
            
            .Range("H1").Value = "Discount Price"
            .Range("I1").Value = "line class"
            .Range("J1").Value = "class"
            .Range("K1").Value = "template"
        End With
        Application.ScreenUpdating = True
        Call MsgBox("Format macro completed", vbInformation + vbOKOnly, "Format Macro")
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •