Hi,
I'm trying to broaden my horizons. Is there a way to mimic Excel's ROW() function in VBA? The following code is close:
But if you have a range that spans more than two rows and hit Ctrl + Enter, it will only output the top row of the range.
That's not its only bug. For example, if you use it on a single cell (say A10, in which case the result is correctly 10), then select a row and delete it (say 5:5), MYROW() will take on the row number of the deleted row (5, in this example).
If you're up for it, is there a way to design a formula that outputs the formula of a targeted cell? Like my ROW()-mimicking function above, the following code is a start, but it has similar drawbacks:
Is there a way to do this?
Thanks for your help.
I'm trying to broaden my horizons. Is there a way to mimic Excel's ROW() function in VBA? The following code is close:
Code:
Function MYROW()
MYROW = Selection.Row
End Function
That's not its only bug. For example, if you use it on a single cell (say A10, in which case the result is correctly 10), then select a row and delete it (say 5:5), MYROW() will take on the row number of the deleted row (5, in this example).
If you're up for it, is there a way to design a formula that outputs the formula of a targeted cell? Like my ROW()-mimicking function above, the following code is a start, but it has similar drawbacks:
Code:
Function GETFORMULA(ByVal Address)
Dim myformula, leftmostbracket, rightmostbracket, mytarget
myformula = Selection.Formula
leftmostbracket = Application.Find("(", myformula)
rightmostbracket = Application.Find(")", myformula)
mytarget = Mid(myformula, leftmostbracket + 1, _
rightmostbracket - leftmostbracket - 1)
GETFORMULA = Range(mytarget).Formula
End Function
Thanks for your help.