Sub AddGrossProfitColumn()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Set ws = ActiveSheet ' Or specify your sheet: Worksheets("Sheet1")
' Find the column index for "Revenue (USD)" and "Cost of Goods Sold (COGS)"
Dim revenueCol As Long, cogsCol As Long, insertCol As Long
revenueCol = ws.Rows(1).Find("Revenue (USD)").Column
cogsCol = ws.Rows(1).Find("Cost of Goods Sold (COGS)").Column
' Insert new column to the right of Revenue
insertCol = revenueCol + 1
ws.Columns(insertCol).Insert Shift:=xlToRight
ws.Cells(1, insertCol).Value = "Gross Profit"
' Get last row with data
lastRow = ws.Cells(ws.Rows.Count, revenueCol).End(xlUp).Row
' Loop through each row to calculate Gross Profit
For i = 2 To lastRow
ws.Cells(i, insertCol).Formula = "=" & ws.Cells(i, revenueCol).Address & "-" & ws.Cells(i, cogsCol).Address
Next i
MsgBox "Gross Profit column added successfully!"
End Sub