Is there a way to not print the pdf if I enter the Code/Reference to Column B and today is Saturday and the Bank from Column G is PNB it will not loop to print the pdf instead just print the other if not PNB and saturday today. This is my codes:
Sub PrintPDF()
Dim WSDATA As Worksheet
Dim WSFormat As Worksheet
Dim LastRow As Long
Dim Batch As String
Dim fname As Variant
Dim exportRange As Range
'Path = "D:DesktopTEST"
Set WSDATA = ThisWorkbook.Sheets("Data")
Set WSFormat = ThisWorkbook.Sheets("DV Format")
Set exportRange = WSFormat.Range("$A$1:$AD$50")
Path = WSDATA.Range("C3").Value
Batch = WSDATA.Range("C2").Value
LastRow = WSDATA.Range("B" & Rows.Count).End(xlUp).Row
For i = 5 To LastRow
Code = WSDATA.Range("B" & i)
If Code <> "" Then
Bank = WSDATA.Range("G" & i)
fname = Code & " " & Bank
SDate = WSDATA.Range("D" & i).Value
If SDate = "" Then
SDate = UCase(Format((Date - 1), "MMMMDD.YYYY"))
Else
SDate = Replace(Replace(UCase(SDate), " ", ""), ",", ".")
End If
'AMOUNT
WSFormat.Range("W16").Value = WSDATA.Range("C" & i).Value
'PURPOSE
WSFormat.Range("B16").Value = WSDATA.Range("E" & i).Value
'BName
WSFormat.Range("B12").Value = WSDATA.Range("F" & i).Value
'Bank
WSFormat.Range("M13").Value = WSDATA.Range("G" & i).Value
'AccountName
WSFormat.Range("N12").Value = WSDATA.Range("H" & i).Value
'AccountNumber
WSFormat.Range("R13").Value = WSDATA.Range("I" & i).Value
'ModeOfPayment
WSFormat.Range("Z13").Value = WSDATA.Range("J" & i).Value
'Company
WSFormat.Range("E8").Value = WSDATA.Range("K" & i).Value
'Department
WSFormat.Range("E9").Value = WSDATA.Range("L" & i).Value
'Date
WSFormat.Range("W8").Value = WSDATA.Range("C1").Value
'SAVE PDF
exportRange.ExportAsFixedFormat Type:=xlTypePDF, IgnorePrintAreas:=False, Filename:=Path & fname & " " & SDate & "-" & Batch, OpenAfterPublish:=False
End If
Next i
End Sub
Im expecting if today is Saturday, If All Banks from Column G is PNB it will not loop to print the PDF.
Domingo Ballesil Jr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.