Nice to meet all the fellows.
I am new to excel Macro VBA, and I just tried to write my first VBA code for the user defined function, however, its not 100% working as the way I would like it to.
I am trying to create a formula to copy the value of next right cell into current activecell, and if the next right cell is blank, copy the value from the one above of the current activecell. (like the screenshot below, the yellow part is the result I want)
Name: Capture.JPG Views: 0 Size: 28.2 KB
Below is my vba code for the function
Function CopyfromNext(x As String) As String
If x <> "" Then
CopyfromNext = ActiveCell(1, 2).Value
Else
CopyfromNext = ActiveCell(0, 1).Value
End If
End Function
It is working fine if I run the code from the vba editor ( running the function each time separately for each cell).
However, if I run the function from the excel function list (just like the excel build in functions) and I drag and copy the formula down to the column ( like the way people normally run for the vlookup), it is not give me correct value (my excel in auto calculation).
Could anyone help me to find why that, I really can’t figure out.
Thanks
Bookmarks