Round function in Excel, worksheet function vs VBA

It’s a known issue. The VBA Round() function uses Banker’s rounding while the spreadsheet cell function uses arithmetic rounding. Check the details here: PRB: Round Function different in VBA 6 and Excel Spreadsheet The workaround proposed by Microsoft is to write a custom function to get the desired results. Banker’s rounding always rounds 0.5 to … Read more

Excel Reference To Current Cell

Several years too late: Just for completeness I want to give yet another answer: First, go to Excel-Options -> Formulas and enable R1C1 references. Then use =CELL(“width”, RC) RC always refers the current Row, current Column, i.e. “this cell”. Rick Teachey’s solution is basically a tweak to make the same possible in A1 reference style … Read more

How do I slice an array in Excel VBA?

Application.WorksheetFunction.Index(array, row, column) If you specify a zero value for row or column, then you’ll get the entire column or row that is specified. Example: Application.WorksheetFunction.Index(array, 0, 3) This will give you the entire 3rd column. If you specify both row and column as non-zero, then you’ll get only the specific element. There is no … Read more

Last non-empty cell in a column

Using following simple formula is much faster =LOOKUP(2,1/(A:A<>””),A:A) For Excel 2003: =LOOKUP(2,1/(A1:A65535<>””),A1:A65535) It gives you following advantages: it’s not array formula it’s not volatile formula Explanation: (A:A<>””) returns array {TRUE,TRUE,..,FALSE,..} 1/(A:A<>””) modifies this array to {1,1,..,#DIV/0!,..}. Since LOOKUP expects sorted array in ascending order, and taking into account that if the LOOKUP function can not … Read more