I am trying to add a sum if for every row bases on column header. below is my code

hulkvz

New Member
Joined
Mar 15, 2021
Messages
3
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Sum units is expected result - there are over 2000 lines and i need to sum all per row with heading of "units"

VBA Code:
Sub GPSUM()
Columns("k:k").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("k5").Select
    

ActiveCell.FormulaR1C1 = "SumIf(Range("e1:AP1"), Range("*Unit*").Value, Range("e2:AP2"))"

what i am trying to achieve is to sum all cells in a row that has a header like "unit"
The amount of rows can be over 2000. I am stuck!!!!

efghijk
Units - 2021-01Sales -2021-01Units - 2021-02Sales -2021-02Units - 2021-02Sales -2021-03total sum for units
1234569
78912318
45678918
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub GPSUM()
   Columns("k:k").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
   Range("k5:K" & Range("E" & Rows, Count).End(xlUp).Row).Formula = "SumIf(e$1:J$1, ""*Unit*"", e2:J2)"
End Sub
 
Upvote 0
Fixed by

VBA Code:
Columns("f:f").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("f4").Select
    ActiveCell.FormulaR1C1 = "Total Sales Summery"
 Range("f5").Select

Range("f5").formula = "=SumIf(g$4:g$4, ""*Unit*"", g5:g5)"
 
Upvote 0
That is not doing anything like what you asked for. :confused:
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,782
Members
449,123
Latest member
StorageQueen24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top