![]() |
Two problems inserting a formula
Hi,
I have a piece of code that inserts a formula into a specific cell on a line. The formula looks at five possible values on the same line, calculates the average of the highest three of them and then uses this output (along with another value) to look up a new value from a table (this is what the offset does). I am happy that the formula works as intended - when I enter it manually into the sheet it works. What I can't work out is how to assign the formula to the necessary cell - I keep getting an error when I use the code below: sFormula = "=IF(ISERROR(OFFSET('User Data'!$D$13,-C" & lLineCount & ",ROUND((LARGE(D" & lLineCount & ":H" & lLineCount & ",1)+LARGE(D" & lLineCount & ":H" & lLineCount & ",2)+LARGE(D" & lLineCount & ":H" & lLineCount & ",3))/3,0)))," & Chr(34) & ",OFFSET('User Data'!$D$13,-C" & lLineCount & ",ROUND((LARGE(D" & lLineCount & ":H" & lLineCount & ",1)+LARGE(D" & lLineCount & ":H" & lLineCount & ",2)+LARGE(D" & lLineCount & ":H" & lLineCount & ",3))/3,0)))" Range("I" & lLineCount).Value = sFormula Two questions: 1) what is the correct syntax to get the Range... line working? 2) the formula feels really clunky, can anyone suggest anything that simplifies it? TIA Dave |
Two problems inserting a formula
I think you need 2 Chr(34)'s:
Chr(34) & Chr(34) -- Jim "Risky Dave" wrote in message ... | Hi, | | I have a piece of code that inserts a formula into a specific cell on a | line. The formula looks at five possible values on the same line, calculates | the average of the highest three of them and then uses this output (along | with another value) to look up a new value from a table (this is what the | offset does). | | I am happy that the formula works as intended - when I enter it manually | into the sheet it works. What I can't work out is how to assign the formula | to the necessary cell - I keep getting an error when I use the code below: | | sFormula = "=IF(ISERROR(OFFSET('User Data'!$D$13,-C" & lLineCount & | ",ROUND((LARGE(D" & lLineCount & ":H" & lLineCount & ",1)+LARGE(D" & | lLineCount & ":H" & lLineCount & ",2)+LARGE(D" & lLineCount & ":H" & | lLineCount & ",3))/3,0)))," & Chr(34) & ",OFFSET('User Data'!$D$13,-C" & | lLineCount & ",ROUND((LARGE(D" & lLineCount & ":H" & lLineCount & | ",1)+LARGE(D" & lLineCount & ":H" & lLineCount & ",2)+LARGE(D" & lLineCount & | ":H" & lLineCount & ",3))/3,0)))" | Range("I" & lLineCount).Value = sFormula | | Two questions: | 1) what is the correct syntax to get the Range... line working? | 2) the formula feels really clunky, can anyone suggest anything that | simplifies it? | | TIA | | Dave |
All times are GMT +1. The time now is 07:49 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com