Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there,
so from my vb.net code i send this through to excel
FormulaR1C1 = "=SUM(" & pubfuncCheckNull(privFuncRetrieveExcelColumnName(i, 2) & ":" & privFuncRetrieveExcelColumnName(i, dtaTable.Rows.Count + 1)) & ")"


which basically just says SUM(B3:B4) in vb but when it gets to excel, it reads SUM('B3':'B4') and doesn't work out the sum. I know its a long shot but can someone tell me what i'm doing wrong? is it cause i use a string concatenation in the sum method?
Thanks in advance
Posted

1 solution

I would look at the definition of privFuncRetrieveExcelColumnName - it looks to be encapsulating the Cell IDs.
I assume it is one of yours - google couldn't find it.
 
Share this answer
 
Comments
Ace_Hardlight 22-Aug-11 6:02am    
pubfuncCheckNull and privFuncRetrieveExcelColumnName are my own yes. pubfuncCheckNull checks that the input string is not empty it works fine. privFuncRetrieveExcelColumnName retrieves the column e.g. "A","B" etc and returns it as a string.
OriginalGriff 22-Aug-11 6:06am    
Check the value returned (either use the debugger to breakpoint and have a look at the string FormulaR1C1, or write it to the console) - I suspect that privFuncRetrieveExcelColumnName returns a string encapsulated in quotes, rather than just as the bare string.
Ace_Hardlight 22-Aug-11 6:08am    
yes that's right it does return a string encapsulated in quotes like "B4". How do i remove the quotes then?
OriginalGriff 22-Aug-11 6:12am    
Personally? I would create a second method that didn't generate them in the first place, then call it from the one that does... :laugh:
But if that isn't an option, there is always
string s = "SUM('B3':'B4')";
s = s.Replace("'", "");
Ace_Hardlight 22-Aug-11 6:24am    
if my function returns "B2:B3" exactly like that, would it be a problem? cause my code would then read "=SUM(" & "B3:B4" & ")".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900