only one code executes after i merged two codes together

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I have merged two codes together but the seocnd part of the code does not execute / run

I press my PRINT 1 INVOICE BUTTON on my worksheet.
The invoice is then printed.
I see the msgbox CLEAR INVOICE AFTER PRINTING.
I press the OK button but after the msgbox is closed then this is where the next part does not execute,see text in red.

Many thanks


Code:
Private Sub Print_One_Invoice_Click()

    If Range("N18") = "" Then
        MsgBox ("PLEASE SELECT A PAYMENT TYPE "), vbCritical, "Payment Type Not Selected"
    Else
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        MsgBox "CLEAR INVOICE AFTER PRINTING"
        
[COLOR=#ff0000]            Dim strFileName As String[/COLOR]
[COLOR=#ff0000]    [/COLOR]
[COLOR=#ff0000]    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\" & Range("N4").Value & ".pdf"[/COLOR]
[COLOR=#ff0000]    If Dir(strFileName) <> vbNullString Then[/COLOR]
[COLOR=#ff0000]        MsgBox "INVOICE " & Range("N4").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly[/COLOR]
[COLOR=#ff0000]        Exit Sub[/COLOR]
[COLOR=#ff0000]    [/COLOR]
[COLOR=#ff0000]    [/COLOR]
[COLOR=#ff0000]    With ActiveSheet[/COLOR]
[COLOR=#ff0000]        .PageSetup.PrintArea = "$G$3:$O$61"[/COLOR]
[COLOR=#ff0000]        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False[/COLOR]
[COLOR=#ff0000]        MsgBox "INVOICE " & Range("N4").Value & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly[/COLOR]
[COLOR=#ff0000]        Range("G27:N36").ClearContents[/COLOR]
[COLOR=#ff0000]        Range("G46:G48").ClearContents[/COLOR]
[COLOR=#ff0000]        Range("G47:I51").ClearContents[/COLOR]
[COLOR=#ff0000]        Range("N18").ClearContents[/COLOR]
[COLOR=#ff0000]        Range("N4").Value = Range("N4").Value + 1[/COLOR]
[COLOR=#ff0000]        Worksheets("INV2").Range("N4").Value = Range("N4").Value[/COLOR]
[COLOR=#ff0000]        Range("G13").ClearContents[/COLOR]
[COLOR=#ff0000]        Range("G13").Select[/COLOR]
[COLOR=#ff0000]        ActiveWorkbook.Save[/COLOR]
[COLOR=#ff0000]    End With[/COLOR]
[COLOR=#ff0000]    End If[/COLOR]
[COLOR=#ff0000]    End If[/COLOR]
[COLOR=#ff0000]End Sub


[/COLOR]
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I have changed the message line & removed the exit sub but it still does the same as before.


Code:
Private Sub Print_One_Invoice_Click()

    If Range("N18") = "" Then
        MsgBox ("PLEASE SELECT A PAYMENT TYPE "), vbCritical, "Payment Type Not Selected"
    Else
        ActiveWindow.SelectedSheets.PrintOut Copies:=1
        MsgBox "ONCE INVOICE HAS PRINTED CLICK OK" & vbNewLine & vbNewLine & "TO SAVE INVOICE & CLEAR INFO", vbExclamation + vbOKOnly, "PRINT SAVE & CLEAR MESSAGE"
        
            Dim strFileName As String


    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\" & Range("N4").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "INVOICE " & Range("N4").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly


    With ActiveSheet
        .PageSetup.PrintArea = "$G$3:$O$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        MsgBox "INVOICE " & Range("N4").Value & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly
        Range("G27:N36").ClearContents
        Range("G46:G48").ClearContents
        Range("G47:I51").ClearContents
        Range("N18").ClearContents
        Range("N4").Value = Range("N4").Value + 1
        Worksheets("INV2").Range("N4").Value = Range("N4").Value
        Range("G13").ClearContents
        Range("G13").Select
        ActiveWorkbook.Save
    End With
    End If
    End If
End Sub
 
Upvote 0
Looks like your Ifs and End Ifs are in the wrong places to me. What does this do:

Code:
If Range("N18") = "" Then
    MsgBox ("PLEASE SELECT A PAYMENT TYPE "), vbCritical, "Payment Type Not Selected"
    Exit Sub
Else
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    MsgBox "CLEAR INVOICE AFTER PRINTING"
End If
        
Dim strFileName As String

strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\" & Range("N4").Value & ".pdf"
If Dir(strFileName) <> vbNullString Then
    MsgBox "INVOICE " & Range("N4").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly
    Exit Sub
Else
    With ActiveSheet
        .PageSetup.PrintArea = "$G$3:$O$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        MsgBox "INVOICE " & Range("N4").Value & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly
        Range("G27:N36").ClearContents
        Range("G46:G48").ClearContents
        Range("G47:I51").ClearContents
        Range("N18").ClearContents
        Range("N4").Value = Range("N4").Value + 1
        Worksheets("INV2").Range("N4").Value = Range("N4").Value
        Range("G13").ClearContents
        Range("G13").Select
        ActiveWorkbook.Save
    End With
End If
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top