I can't get cellRange to work.
I've tried adding a background color to the cell and now changing the font.
Run this in Solidworks.
I've tried adding a background color to the cell and now changing the font.
Run this in Solidworks.
VBA Code:
' Steg 4: Infoga tom rad och lägg till formel i G
startRow = lastRow ' Start at the end
For i = lastRow To 2 Step -1
' Kontrollera om värdet i kolumn C ändras
If ws.Cells(i, 3).Value <> ws.Cells(i - 1, 3).Value Then
' Hämta värdet från kolumn C innan tom rad infogas
currentValue = ws.Cells(i, 3).Value
' Infoga en tom rad
ws.Rows(i).Insert Shift:=xlDown
' Skapa formel på den tomma raden i G (kolumn 7)
sumRange = "E" & startRow + 1 & ":E" & i + 1
ws.Cells(i + 1, 7).Formula = "=ROUNDUP(SUM(" & sumRange & ") / 6000, 0)"
' Sätt värdet i H-kolumnen (kolumn 8) till samma som i C-kolumnen på den nya tomma raden
ws.Cells(i + 1, 8).Value = currentValue ' H = C på samma rad
' Gör texten fet och större i både G och H
Dim cellRange As Range
Set cellRange = ws.Range(ws.Cells(i + 1, 7), ws.Cells(i + 1, 8))
With cellRange
.Interior.Color = RGB(144, 238, 144) ' Ljusgrön färg
.Font.Bold = True ' Fet text
.Font.Size = 12 ' Större textstorlek (ändra vid behov)
With .Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With