Reputation: 103
I am quite new to VBA, so please bear with me here.
I need to make a sum based on a few column headers, the position that these columns are placed in are always different (e.g. FRT column might be in B one time and another time in column D).
However the three components are always the same, but can be in different columns, see below for what I want to accomplish.
What is the best way to go about this? I want to try to avoid use of fixed formulas as the data range is dynamic.
Upvotes: 1
Views: 100
Reputation: 9894
M.Douda answer is much shorter but I thought I would offer a variation
=SUMPRODUCT((($A$1:$D$1)="FRT")*(A2:D2)+(($A$1:$D$1)="SC")*(A2:D2)+(($A$1:$D$1)="NK")*(A2:D2))
place that in your Net FRT first cell and copy down.
Upvotes: 1
Reputation: 574
I don't think that VBA is needed for this task.
=SUM(SUMIFS(2:2;$1:$1;{"FRT";"SC";"NK"}))
This formula sums sums of all columns labeled FRT SC or NK.
Upvotes: 2