Row 1, Column E thru Z contain my headers. Sometimes the headers are merged across multiple columns and sometimes not. The data will be in rows 2 thru whatever.
For Example:
The column header in E1:G1 has Site 1. E2:G2 contains the data for Site 1. Thus E2=5, F2=13, G2=5. So the total for Site 1 is 23.
The column header in H1 has Site 2. H2 contains the data for Site 2. Thus H2=12. So the total for Site 2 is 12.
The column header in I1:M1 has Site 3. I2:M2 contains the data for Site 3. Thus I2=4, J2=7, K2=0, L2=15, M2=5. So the total for Site 3 is 31.
...and so on thru column Z
In column C I will need the Average for all Sites.
There will be many rows but I'm trying to figure out the logic so I'm just coding for row 2.
What I've been trying to do is determine what cells are merged and which are not. Unfortunately, as I loop thru the cells I haven't figured out how to avoid repeating cells references because of the merged cells. Here is the code and I look at the results in the Immediate Window:
The results look like:
$E$1:$G$1
$E$1:$G$1
$E$1:$G$1
$H$1
$I$1:$L$1
$I$1:$L$1
$I$1:$L$1
$I$1:$L$1
$M$1:$P$1
$M$1:$P$1
$M$1:$P$1
$M$1:$P$1
$Q$1
$R$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$Y$1
$Z$1
But I want the results to look like:
$E$1:$G$1
$H$1
$I$1:$L$1
$M$1:$P$1
$Q$1
$R$1
$S$1:$X$1
$Y$1
$Z$1
Any suggestions?
For Example:
The column header in E1:G1 has Site 1. E2:G2 contains the data for Site 1. Thus E2=5, F2=13, G2=5. So the total for Site 1 is 23.
The column header in H1 has Site 2. H2 contains the data for Site 2. Thus H2=12. So the total for Site 2 is 12.
The column header in I1:M1 has Site 3. I2:M2 contains the data for Site 3. Thus I2=4, J2=7, K2=0, L2=15, M2=5. So the total for Site 3 is 31.
...and so on thru column Z
In column C I will need the Average for all Sites.
There will be many rows but I'm trying to figure out the logic so I'm just coding for row 2.
What I've been trying to do is determine what cells are merged and which are not. Unfortunately, as I loop thru the cells I haven't figured out how to avoid repeating cells references because of the merged cells. Here is the code and I look at the results in the Immediate Window:
Code:
Sub test7()
For x = 5 To 26
Cells(1, x).Select
If ActiveCell.MergeArea.Columns.Count = 1 Then
Debug.Print Cells(1, x).Address
Else
If ActiveCell.MergeArea.Columns.Count > 2 Then
Debug.Print ActiveCell.MergeArea.Address
End If
End If
Next x
Range("c" & 2).Select
End Sub
The results look like:
$E$1:$G$1
$E$1:$G$1
$E$1:$G$1
$H$1
$I$1:$L$1
$I$1:$L$1
$I$1:$L$1
$I$1:$L$1
$M$1:$P$1
$M$1:$P$1
$M$1:$P$1
$M$1:$P$1
$Q$1
$R$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$S$1:$X$1
$Y$1
$Z$1
But I want the results to look like:
$E$1:$G$1
$H$1
$I$1:$L$1
$M$1:$P$1
$Q$1
$R$1
$S$1:$X$1
$Y$1
$Z$1
Any suggestions?