Solved Highlight cell on print

oxicottin

Learning by pecking away....
Local time
Yesterday, 23:31
Joined
Jun 26, 2007
Messages
883
Hello, I have a Excell sheet that I use to print either 5 days or 4 days worth of copy's using a button on sheets heading. Anyways I need the VBA on the 5th print (Button Print 5 Days) which the date would be end on a Friday to highlight cell E7 for that print then change tit back to normal. How can I do this?

Attached is the workbook/sheet
 

Attachments

Keep track of the print number.
Set the cell backcolour when on 5
Print the last copy
Unset the cell backcolour or do not save the workbook.
 
Last edited:
Keep track of the print number.
Set the cell backcolour when on 5
Print the last copy
Unset the cell backcolour or do not save the workbook.
@Gasman this works but is there a better way?

Code:
Sub Test()
    
    Dim x As Integer
    
    With Sheets("Plant Attendance")
        For x = 1 To 5
            If x = 5 Then
                .Range("E7").Select
                Selection.Interior.Color = vbRed
                .PrintOut
                Selection.Interior.Color = vbWhite
            Else
                .PrintOut
                .Range("E7") = .Range("E7") + 1
            End If
            Next x
            
        End With
        
'Increment
        ActiveSheet.Range("E7").Value = ActiveSheet.Range("E7").Value + 2
        ActiveSheet.Calculate
    End Sub
 
Yes, probably not saving the workbook?
Code:
Sub Test()
    
    Dim x As Integer
    
    With Sheets("Plant Attendance")
        For x = 1 To 5
            If x = 5 Then
                .Range("E7")..Interior.Color = vbRed
             End If
                .PrintOut
            Next x
        End With
        
'Increment
        ActiveSheet.Range("E7").Value = ActiveSheet.Range("E7").Value + 2
        ActiveSheet.Calculate
    End Sub
 
Yes, probably not saving the workbook?
Code:
Sub Test()
  
    Dim x As Integer
  
    With Sheets("Plant Attendance")
        For x = 1 To 5
            If x = 5 Then
                .Range("E7")..Interior.Color = vbRed
             End If
                .PrintOut
            Next x
        End With
      
'Increment
        ActiveSheet.Range("E7").Value = ActiveSheet.Range("E7").Value + 2
        ActiveSheet.Calculate
    End Sub

Yes im saving the workbook so I always have the last date used in my cell E7, Below is better looking VB?

Code:
Sub Test()
   
    Dim x As Integer
   
    With Sheets("Plant Attendance")
        For x = 1 To 5
           
            If x = 5 Then
                .Range("E7").Interior.ColorIndex = 35  'Magenta
                .PrintOut
                .Range("E7").Interior.ColorIndex = -4142  ' Interior.ColorIndex = -4142 is enumeration to clear the background or fill color.
            Else
                .PrintOut
                .Range("E7") = .Range("E7") + 1
            End If
            Next x
        End With
       
'Increment
        ActiveSheet.Range("E7").Value = ActiveSheet.Range("E7").Value + 2
        ActiveSheet.Calculate
        ActiveSheet.Save
    End Sub
 

Users who are viewing this thread

Back
Top Bottom