I am pretty new in VBA in excel. How can I add shape in every cell that contain "Late"?
Please help. Thanks.
Sub InsertShapeLateDays()
Dim ws As Worksheet
Dim LastRow As Long
Dim LateCount As Integer
Dim LastColumn As Long
Dim i As Long
Dim lateCell As Range
Dim lateShape As Shape
Set ws = ThisWorkbook.Worksheets("Attendance")
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
LastColumn = ws.Cells(1, Columns.Count).End(xlToLeft).Column
LateCount = 0
For i = 2 To LastRow ' Assuming row 1 is the header
If ws.Cells(i, LastColumn).Value = "Late" Then
LateCount = LateCount + 1
Set lateCell = ws.Cells(i, LastColumn)
Set lateShape = ws.Shapes.AddShape(msoShapeIsoscelesTriangle, _
lateCell.Left, lateCell.Top, lateCell.Width, lateCell.Height)
lateShape.Fill.ForeColor.RGB = RGB(0, 0, 0) ' Red color
End If
Next i
MsgBox "The person was late " & LateCount & " times."
End Sub
This code only insert shape in the last column that contains "Late"
Here is my screenshot.
Please help.
Please help. Thanks.
Sub InsertShapeLateDays()
Dim ws As Worksheet
Dim LastRow As Long
Dim LateCount As Integer
Dim LastColumn As Long
Dim i As Long
Dim lateCell As Range
Dim lateShape As Shape
Set ws = ThisWorkbook.Worksheets("Attendance")
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
LastColumn = ws.Cells(1, Columns.Count).End(xlToLeft).Column
LateCount = 0
For i = 2 To LastRow ' Assuming row 1 is the header
If ws.Cells(i, LastColumn).Value = "Late" Then
LateCount = LateCount + 1
Set lateCell = ws.Cells(i, LastColumn)
Set lateShape = ws.Shapes.AddShape(msoShapeIsoscelesTriangle, _
lateCell.Left, lateCell.Top, lateCell.Width, lateCell.Height)
lateShape.Fill.ForeColor.RGB = RGB(0, 0, 0) ' Red color
End If
Next i
MsgBox "The person was late " & LateCount & " times."
End Sub
This code only insert shape in the last column that contains "Late"
Here is my screenshot.
Please help.