Results 1 to 5 of 5

Help: Macro works...But not on pressing button

Threaded View

MarkBrink Help: Macro works...But not... 08-22-2017, 07:58 AM
CK76 Re: Help: Macro works...But... 08-22-2017, 08:03 AM
MarkBrink Re: Help: Macro works...But... 08-22-2017, 08:10 AM
CK76 Re: Help: Macro works...But... 08-22-2017, 08:18 AM
MarkBrink Re: Help: Macro works...But... 08-22-2017, 08:21 AM
  1. #1
    Registered User
    Join Date
    08-22-2017
    Location
    Holland
    MS-Off Ver
    2016
    Posts
    3

    Help: Macro works...But not on pressing button

    Dear forum familie, (SOLVED, Thanks)

    I'm working on a excel project and i'm a bit stuck.

    I made a VBA script works fine if i call the macro from within the visual basic UI. But when i assign a button on that same macro it gives me a 400 error or it runs a part of it.

    One button works fine tho, but why the errors on other buttons?

    Anyone ever had such problem?


    Hope you guys can help,

    Mark

    Below coding (not that it's necessary it works, only the buttons are doing weird...)

    Sub Protocol_print(Optional PrPr As String)
    
    
    Dim rng As Range, cell As Range
     'switch of updating to speed your code & stop irritating flickering
    Application.ScreenUpdating = False
    Application.Cursor = xlWait
    Application.DisplayStatusBar = True
    Application.StatusBar = "Protocollen wordt klaargemaakt..."
    
    
    Worksheets("PROTOCOL N2").Unprotect Password:="secret"
    Worksheets("PROTOCOL N3").Unprotect Password:="secret"
    
    
    
    
    If PrPr = "Ma" Then
    Set rng = Range("C5:C12")
    
    
    ElseIf PrPr = "Di" Then
    Set rng = Range("C17:C24")
    
    
    ElseIf PrPr = "Wo" Then
    Set rng = Range("C29:C36")
    
    
    ElseIf PrPr = "Do" Then
    Set rng = Range("C41:C48")
    
    
    ElseIf PrPr = "Vr" Then
    Set rng = Range("C53:C60")
    End If
    
    
    For Each cell In rng
    
    
    If cell.Value = "" Then
    Exit For
    
    
    End If
    
    
    opleiding = Application.WorksheetFunction.VLookup(cell.Value, Blad2.Range("A3:H147"), 4, False)
    
    
    If opleiding = "ZWBA" Or opleiding = "ZWBR" Or opleiding = "ZWBB" Then
    Worksheets("PROTOCOL N3").Select
    Range("ProtoN3_Naam").Value = cell.Value
    Range("ProtoN3_OV").Value = Application.WorksheetFunction.VLookup(cell.Value, Blad2.Range("A3:H147"), 2, False)
    
    
    If opleiding = "ZWBA" Then
    Range("ProtoN3_BA").Value = "X"
    
    
    ElseIf opleiding = "ZWBR" Then
    Range("ProtoN3_BR").Value = "X"
    
    
    ElseIf opleiding = "ZWBB" Then
    Range("ProtoN3_BB").Value = "X"
    
    
    End If
    
    
    ElseIf opleiding = "UBB" Or opleiding = "UBR" Or opleiding = "UBA" Then
    Worksheets("PROTOCOL N2").Select
    Range("ProtoN2_Naam").Value = cell.Value
    Range("ProtoN2_OV").Value = Application.WorksheetFunction.VLookup(cell.Value, Blad2.Range("A3:H147"), 2, False)
    
    
    If opleiding = "UBA" Then
    Range("ProtoN2_BA").Value = "X"
    
    
    ElseIf opleiding = "UBR" Then
    Range("ProtoN2_BR").Value = "X"
    
    
    ElseIf opleiding = "UBB" Then
    Range("ProtoN2_BB").Value = "X"
    
    
    End If
    
    
    End If
    
    
      'Printen
            Range("A1:D35").Select
            ActiveSheet.PageSetup.PrintArea = ""
            With ActiveSheet.PageSetup
              .LeftMargin = Application.InchesToPoints(0.6)
              .RightMargin = Application.InchesToPoints(0.4)
              .TopMargin = Application.InchesToPoints(0.75)
              .BottomMargin = Application.InchesToPoints(0.75)
              .HeaderMargin = Application.InchesToPoints(0.3)
              .FooterMargin = Application.InchesToPoints(0.3)
              .PrintHeadings = False
              .PrintGridlines = False
              .PrintComments = xlPrintNoComments
              .PrintQuality = 600
              .CenterHorizontally = False
              .CenterVertically = False
              .Orientation = xlPortrait
              .Draft = False
              .PaperSize = xlPaperA4
              .FirstPageNumber = xlAutomatic
              .Order = xlDownThenOver
              .BlackAndWhite = False
              .Zoom = 85
              .PrintErrors = xlPrintErrorsDisplayed
              .OddAndEvenPagesHeaderFooter = False
              .DifferentFirstPageHeaderFooter = False
              .ScaleWithDocHeaderFooter = True
              .AlignMarginsHeaderFooter = True
                .FitToPagesWide = 1
                .FitToPagesTall = 1
         
            End With
            Selection.PrintOut Copies:=1, Collate:=True
            
    Range("ProtoN2_BA, ProtoN2_BR, ProtoN2_BB").Value = ""
    Range("ProtoN3_BA, ProtoN3_BR, ProtoN3_BB").Value = ""
    
    
    Next cell
    
    
    
    
    
    
    
    
      
        Application.Cursor = xlDefault
        Application.StatusBar = False
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
       
       Worksheets("Planning - Praktijk").Activate
       
    
    
            
       
       Worksheets("PROTOCOL N2").Protect Password:="secret"
        Worksheets("PROTOCOL N3").Protect Password:="secret"
       
       MsgBox "Protocollen afgedrukt!"
        
      
    
    
    End Sub
    And the call functions

    Sub Protocol_maandag()
    Dim PrPr As String
    
    
    PrPr = "Ma"
    Protocol_print (PrPr)
         
    End Sub
    
    
    Sub Protocol_dinsdag()
    Dim PrPr As String
    
    
    PrPr = "Di"
    Protocol_print (PrPr)
         
    End Sub
    
    
    Sub Protocol_woensdag()
    Dim PrPr As String
    
    
    PrPr = "Wo"
    Protocol_print (PrPr)
         
    End Sub
    
    
    Sub Protocol_donderdag()
    Dim PrPr As String
    
    
    PrPr = "Do"
    Protocol_print (PrPr)
         
    End Sub
    
    
    Sub Protocol_vrijdag()
    Dim PrPr As String
    
    
    PrPr = "Vr"
    Protocol_print (PrPr)
         
    End Sub
    Last edited by MarkBrink; 08-22-2017 at 08:11 AM. Reason: Solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] SUMPRODUCT works with F9 but pressing ENTER results in #VALUE!
    By ChasGrad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2016, 11:38 PM
  2. Auto call macro without pressing button
    By skhari in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-17-2015, 08:56 PM
  3. Replies: 1
    Last Post: 09-14-2014, 02:10 PM
  4. show area when pressing macro button
    By ossa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2012, 09:19 AM
  5. Macro to create form by pressing button
    By nani_nisha06 in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2012, 02:55 PM
  6. Macro to create form by pressing button
    By jesika in forum Access Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2012, 02:35 PM
  7. Pressing a button using a macro
    By Todd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2005, 04:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1