Thanks Chic_Bowdrie for your response!
Sorry for waisting your papar, my mistake, I have "commented" the printing line so it will
NOT print again.
This macro do two things 1) Prints a pay stub and 2) If the cell value is a certain value, in this new example "Email" on the sheet "PaySlip" cell "A3", will it instead of printing a pay stub, email the pay stub, this beacause some employees have email adresses (saving paper-sorry again for wasting yours).
Your concern regarding col "A" on Sheet1 repeating the same value will not happen as these numbers are unique to the worker. To illiminate confusion have I changed the those values to "Email" and "Don't" With that out of the way, let me talk you through the macro.
In this example I only have one instance where it sends a email, I have about 15 workers that will have there's mailed, therefore having to sit and wait for each email notification to count down is driving me out the walls.
It starts with creating a count +1 range in col "AI" sheets1.
Code:
Sheets("Sheet1").Range("AI7:AI" & lastrow).FormulaR1C1 = "=IF(RC1="""",R[-1]C,R[-1]C+1)"
Then it executes a loop using the MaxNum function on the Sheet "PaySlip" for range "A3".
Code:
MaxNum = WorksheetFunction.Max(RngNum)
For i = 1 To MaxNum Step 1 'change maxnum to some small number to test short runs
Range("A3").Value = WorksheetFunction.Index(RngClk, WorksheetFunction.Match(i, RngNum, 0))
Whilst this loop is running will it annalise the value of cell "A3" of sheet "PaySlip" and calculate if it must print or email the pay stub using the " Case" statement.
Code:
'Print this sheet only if cell A3 don't have email address
Select Case Range("A3").Value
'Lena
Case "Email" 'Then email
ThisWorkbook.Sheets("PaySlip").Copy
With ActiveWorkbook
.SendMail Recipients:="[email protected]", _
Subject:="Sal Advise " & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
Case Else
' ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Select
Next i
If "Case" = "Email" in sheets "PaySlip" cell "A3" then will it email sheet, Case Else will it print the sheet.
Please run the code and grind tour teeth at the mail notification.
I have added a simpler attachment with the same code.
Thanks again!