Hi,
In my macro, I am trying to insert an "IF" function into a cell that will average 2 rows if the difference between two cells is "> -2" and average a different two rows if the difference is not ">-2". The cells for which the difference is calculated as well as the ranges that need to be averaged are specified by variables within the macro. The pertinent portion of my macro is:
where,Please Login or Register to view this content.
LastRowWithData is an Integer
TimeClosestToCoolDownLocation is a String (address of cell)
CoolDownStartTimeSecondsLocation is a String (address of cell)
RowClosestToCoolDownTimeInSec is a String (this is a row number determined using an array function earlier in the macro)
Right now, as the macro is written, the following gets inserted into the cell:
=IF(R120C2 - R84C2>-2,AVERAGE("R84C2:R83C2"),AVERAGE("R83C2:R82C2") , which is close to what I need (i.e., the cell addresses and ranges are correct), except for the extra quotes around the two ranges within the AVERAGE function. Because of the extra quotes, I get a "#VALUE!" error in the cell the function is inserted into.
I realize that this is because I have double quotes around the ranges in the actual macro vba code, but if I use only single quotes around the ranges, I get a "Compile error: Expected: end of statement" at the first R (for Row) in the first AVERAGE function. If I remove the quotes all together from around the ranges in the AVERAGE functions, the macro runs, but I get a "Run-Time error '1004': Application-defined or object-defined error".
If anybody can help show me what I am doing wrong, it would be greatly appreciated.
Thank you for the help.
Bookmarks