Option Explicit
Sub test2()
Dim sp As Shape
Dim st As Long, en As Long
Dim i As Long
Dim L As Double, T As Double, W As Double, H As Double
Dim r As Double
Dim datCol As Long, spCol As Long
Const startRow As Long = 2 'without table header
datCol = Columns("I").Column
spCol = Columns("K").Column
For Each sp In ActiveSheet.Shapes
If sp.TopLeftCell.Column = spCol Then
sp.Name = "PIC_125mL-" & sp.TopLeftCell.MergeArea.Row
End If
Next
st = startRow
en = st
For i = startRow + 1 To Cells(Rows.Count, datCol).End(xlUp).Row + 1
If Cells(st, datCol).Value = Cells(i, datCol).Value Then
en = i
On Error Resume Next
If en > st Then ActiveSheet.Shapes("PIC_125mL-" & i).Delete
On Error GoTo 0
Else
Range(Cells(st, spCol), Cells(en, spCol)).Merge
With Cells(st, spCol).MergeArea
L = .Left
T = .Top
H = .Height
W = .Width
With ActiveSheet.Shapes("PIC_125mL-" & st)
.LockAspectRatio = msoTrue
r = WorksheetFunction.Min(W / .Width, H / .Height)
.Left = L + (W - .Width * r) / 2
.Top = T + (H - .Height * r) / 2
.Width = .Width * r
End With
End With
st = i
en = st
End If
Next
End Sub