PDA

View Full Version : VBA for a calculation where the range is dynamic



lgare
12-22-2015, 04:13 AM
Hi,
I have a large data set of student exam results where I am trying to return the result of the calculation =SUM(range)/100, where the range is a dynamic number of exam results (one per row), for each student. As shown in the below example, the range is the Weighted Exam Scores for each student and the result of =SUM(range)/100 should be returned in column 'Weighted Avg.Score' in the first row of each student. Can anyone suggest some VBA code to do this please?






Student Number
Exam Credit



Exam Score



Weighted Exam Score
Weighted Avg. Score


01
20
11
210
8.1


01
20
10
200



01
40
8
320



01
20
4
80



02
10
14
140
12.1


02
10
15
150



02
60
13
780



02
20
7
140



03
20
7
140
10.2


03
40
13
520



03
40
13
520



04
10
12
120
11.9


04
10
13
130



04
50
13
650



04
20
10
200



04
10
9
90



05
40
12
480
10.8


05
40
10
400



05
20
10
200

Bob Phillips
12-22-2015, 04:29 AM
You don't need VBA, a simple formula will suffice


=IF(A2<>A1,SUMIF(A:A,A2,D:D)/100,"")

lgare
12-22-2015, 07:39 AM
This worked beautifully, many thanks!