J JMay Oct 29, 2009 #1 ActiveCell.Formula = "=Counta(Selection.Offset(-1).end(xlUp) & "":"" & Selection.Offset(-1))" 'Top to bottom
ActiveCell.Formula = "=Counta(Selection.Offset(-1).end(xlUp) & "":"" & Selection.Offset(-1))" 'Top to bottom
S Sam Wilson Oct 29, 2009 #2 Replace: "=Counta(Selection.Offset(-1).end(xlUp) & "":"" & Selection.Offset(-1))" with "=Counta(" & Selection.Offset(-1).end(xlUp).address & ":" & Selection.Offset(-1).address & ")" Sam
Replace: "=Counta(Selection.Offset(-1).end(xlUp) & "":"" & Selection.Offset(-1))" with "=Counta(" & Selection.Offset(-1).end(xlUp).address & ":" & Selection.Offset(-1).address & ")" Sam
J Jim Thomlinson Oct 29, 2009 #3 That formula is not valid... Everything is inside the quotes so your formula is exactly what is typed. Additionally the default return value of a range is the value and not the address. You want something more like... ActiveCell.Formula = "=Counta(" & Selection.Offset(-1).end(xlUp).address & ":" & Selection.Offset(-1).address & ")" 'Top to bottom
That formula is not valid... Everything is inside the quotes so your formula is exactly what is typed. Additionally the default return value of a range is the value and not the address. You want something more like... ActiveCell.Formula = "=Counta(" & Selection.Offset(-1).end(xlUp).address & ":" & Selection.Offset(-1).address & ")" 'Top to bottom
J JMay Oct 29, 2009 #4 Jim, Thank you so much - 1) for your fine/understandable explanation and 2) the revised formula - WORKS GREAT!! Jim
Jim, Thank you so much - 1) for your fine/understandable explanation and 2) the revised formula - WORKS GREAT!! Jim
D Dave Peterson Oct 29, 2009 #5 This may not fit, but if you're trying to count the number of cells filled between row 1 and the row above, you could use: activecell.formular1c1 = "=counta(r1c:r[-1]c)") r1c is row 1 of the same column r[-1]c is the row above of the same column If you had headers in rows 1:2 that you wanted to avoid: activecell.formular1c1 = "=counta(r3c:r[-1]c)")
This may not fit, but if you're trying to count the number of cells filled between row 1 and the row above, you could use: activecell.formular1c1 = "=counta(r1c:r[-1]c)") r1c is row 1 of the same column r[-1]c is the row above of the same column If you had headers in rows 1:2 that you wanted to avoid: activecell.formular1c1 = "=counta(r3c:r[-1]c)")