I have a formula that searches for a column header on another sheet, then once its found it goes through some sumifs
. My data roughly looks like this:
1 8 10 11 12
Column E ... Column N ... Column O ... Column AB Column AC Column AD Column AE
Existing CCS data 100.00 100.00 120.00 150.00
The numbers above the column names are significant and I use them to designate columns that are relevant to my formulas. Now, There are really only a few cells that are significant to the loop. Cell A1 has the number of the column I want to terminate on. Cell B1 has the number of the column I want to start from. So If I choose A1=8
and B1=1
, I want the below code to run the sumifs
starting by searching for column 1
, then for column 2
, all the way until column 8
and add all of the values from each loop together and give me the total. Using the above table as an example, if I set A1="12"
and B1="10"
, I want it to spit out 370.00
.
The formula I currently have is this:
=SUMIFS(INDEX('Program Data'!$A:$GA,0,MATCH(A1,'Data'!$1:$1,0)),'Data'!$N:$N,"CCS",
'Data'!$E:$E,"Existing")+SUMIFS(INDEX('Data'!$A:$GA,0,MATCH(A1,'Data'!$1:$1,0)),
'Data'!$N:$N,"CCS",'Data'!$E:$E,"Deep")
The formula above only gives me the total for the column that contains the numerical string in A1
, but I need a total for all columns with the strings from B1 -> A1
.
EDIT
As requested, here is my failing attempt at this loop. Since B1 is essentially always a static number (meaning it will always be 45 or 88 or something), I thought I could create a loop telling it to start at whatever value B1 is and essentially create and drop the formula into the cell as I need it. So for this one, B1=1=z...
Sub LoopingYTD()
Dim z As Integer: z = 1
Dim formulaString2 As String
Do Until z = Range("A1") + 1
If formulaString2 = "" Then
formulaString2 = "="
Else
formulaString2 = formulaString2 & " + "
End If
formulaString2 = formulaString2 + " SUMIFS(INDEX('Data'!A:GA,0,MATCH("
formulaString2 = formulaString2 & """*"" &
formulaString2 = formulaString2 & "z"&" ""
formulaString2 = formulaString2 & """*""" & ",'Data'!1:1,0)),"
formulaString2 = formulaString2 & "'Data'!$N:$N,”CCS”,”
formulaString2 = formulaString2 & “'Data'!$E:$E,”Existing”))"
formulaString2 = formulaString2 & "+ SUMIFS(INDEX('Data'!A:GA,0,MATCH("
formulaString2 = formulaString2 & """*"" &
formulaString2 = formulaString2 & "z"&" ""
formulaString2 = formulaString2 & """*""" & ",'Data'!1:1,0)),"
formulaString2 = formulaString2 & "'Data'!$N:$N,”CCS”,”
formulaString2 = formulaString2 & “Data'!$E:$E, ”Deep”))"
z = z + 1
Loop
Range("B20").Value = formulaString2
I keep getting an "application-defined or object defined error", though I'm not sure what the remedy is for that.
This is based off of a suggestion from an earlier question I asked. Since then, I've been trying to simplify it, as that was a bit messy, so I just want it to search for a single string of numbers. Basically run the code in the link, but instead of some long, convoluted string based on several cells, I just want it to count up until it reaches the value in A1.