Hi there,
I have a really large data file >20000 rows, and I would like to have averages for several columns depending on a person's ID number; however, each person has a different number of rows for each condition, and I'm not sure how to average the array if it's a variable number of rows.
It sounds kind of complicated, but being very new to VBA I'm sure it's just a problem of me not being able to wrap my head around the syntax.
An example of what my data would look like:
A_B__C__D
1 182 362 164
1 313 273
1 350 118 298
1 188 265 109
2 241 124 116
2 376 229 186
2 125 173 176
2 138 351 329
2 288 273 191
3 160 320 189
3 277 314
3 167 313 198
(in my actual file I have ~30 columns though)
And I've started by putting blank rows between subjects (ID numbers) with this code:
Sub Insert_Rows()
Dim lastRow, chkRw As Integer
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For chkRow = lastRow To 2 Step -1
If Range("A" & chkRow) <> Range("A" & chkRow + 1) Then
Range("A" & chkRow + 1).EntireRow.Insert shift = xlDown
End If
Next
End Sub
End Sub
So, ideally what I'd like to do is fill in the blank rows with averages of the above data for each column, for each participant (dependent on the ID column) - the problem is that there's missing data, and a variable number of rows for each person. Following that (if possible!) I'd like to copy those averages onto a separate sheet.
I'm using visual basic, and Open Office Calc 3.2.1/ Excel 2007
Thanks in advance!!!
Rhi
I have a really large data file >20000 rows, and I would like to have averages for several columns depending on a person's ID number; however, each person has a different number of rows for each condition, and I'm not sure how to average the array if it's a variable number of rows.
It sounds kind of complicated, but being very new to VBA I'm sure it's just a problem of me not being able to wrap my head around the syntax.
An example of what my data would look like:
A_B__C__D
1 182 362 164
1 313 273
1 350 118 298
1 188 265 109
2 241 124 116
2 376 229 186
2 125 173 176
2 138 351 329
2 288 273 191
3 160 320 189
3 277 314
3 167 313 198
(in my actual file I have ~30 columns though)
And I've started by putting blank rows between subjects (ID numbers) with this code:
Sub Insert_Rows()
Dim lastRow, chkRw As Integer
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For chkRow = lastRow To 2 Step -1
If Range("A" & chkRow) <> Range("A" & chkRow + 1) Then
Range("A" & chkRow + 1).EntireRow.Insert shift = xlDown
End If
Next
End Sub
End Sub
So, ideally what I'd like to do is fill in the blank rows with averages of the above data for each column, for each participant (dependent on the ID column) - the problem is that there's missing data, and a variable number of rows for each person. Following that (if possible!) I'd like to copy those averages onto a separate sheet.
I'm using visual basic, and Open Office Calc 3.2.1/ Excel 2007
Thanks in advance!!!
Rhi
Last edited: