Hello everyone,

I have been trying to create a macro that inserts a space between different values (per below code), but now I also need the macro to autosum the values in cells K and L, within the grouped/ divided rows.

Grouping code:
 Dim lastrow As Long
     Dim x As Long
     lastrow = Cells(Rows.Count, 1).End(xlUp).Row
     Application.ScreenUpdating = False
 
    For x = lastrow To 2 Step -1
         If Cells(x, 1).Value <> Cells(x - 1, 1).Value Then
             If Cells(x, 1).Value <> "" Then
                 If Cells(x - 1, 1).Value <> "" Then
                     Cells(x, 1).EntireRow.Insert Shift:=xlDown
                 End If
             End If
         End If

     Next x
     Application.ScreenUpdating = True

Below is my very poor attempt for the autosum:

 Dim total As Integer
         total = CInt([=sum("K:L")])
         Cells("P").Activate
         ActiveCell.FormulaR1C1 = total
How would I correct this code, and where would I insert it to make it work, or does that not matter? Thank you in advance for your assistance.