ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
I am using the code shown below but i would like to add an If Else line of code but not sure on how to do it.
The code below will be used the same both times but with or without the additional value added when saved.
Before the file is saved / printed etc i would like the code to check for a value in a cell.
The cell is question is N1
There will be various values in the cell but will only ever consist of 1 letter
The letter im interested in is M
So what i need to add to my existing code If cell N1 ="M" then save the file the same as the line of code shown in blue but with the additional value of *SUS* to the saved output
Else just save it using the blue line of code.
The output will be like my example below depending if cell N1 = M or not
TOM JONES
16-10-2023
ABC 123
or
TOM JONES
16-10-2023
ABC 123
*SUS*
I tried this but my code was incorrect
The code below will be used the same both times but with or without the additional value added when saved.
Before the file is saved / printed etc i would like the code to check for a value in a cell.
The cell is question is N1
There will be various values in the cell but will only ever consist of 1 letter
The letter im interested in is M
So what i need to add to my existing code If cell N1 ="M" then save the file the same as the line of code shown in blue but with the additional value of *SUS* to the saved output
Else just save it using the blue line of code.
The output will be like my example below depending if cell N1 = M or not
TOM JONES
16-10-2023
ABC 123
or
TOM JONES
16-10-2023
ABC 123
*SUS*
Rich (BB code):
Private Sub PurchasedKey_Click()
Dim sPath As String
Dim strFileName As String
Dim sh As Worksheet
If TextBox1 = "" Then
MsgBox "YOU DID NOT ENTER A CUSTOMERS NAME", vbCritical, "NO NAME ENTERED ON SHEET"
TextBox1.SetFocus
Exit Sub
End If
With ThisWorkbook.Worksheets("PRINT LABELS")
.Range("B3") = Me.TextBox1.Text
.Range("E3") = Format(DateSerial(CLng(Me.cboYear.Value), Me.cboMonth.ListIndex + 1, Me.cboDay.Value), "long date")
End With
Unload PrinterForm
With ActiveSheet
If .Range("AB1") = "" Then
MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
Exit Sub
End If
ENTER LINE OF CODE HERE PLEASE
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & " " & .Range("AB1").Value & ".pdf"
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
With ActiveSheet
ActiveWindow.SelectedSheets.PrintOut copies:=1
End With
End With
End Sub
I tried this but my code was incorrect
Rich (BB code):
If .Range("N1") = M Then
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & " " & .Range("AB1").Value & " " & *SUS* ".pdf"
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
Else
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & " " & .Range("AB1").Value & ".pdf"
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End If
With ActiveSheet
ActiveWindow.SelectedSheets.PrintOut copies:=1
Last edited: