Mariel
Mariel

Reputation: 103

SUMIF based on multiple columns

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.

Expected results

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

Answers (2)

Forward Ed
Forward Ed

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.

POC

Upvotes: 1

M.Douda
M.Douda

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

Related Questions