• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Formula added to VBA

rbobcat1

Member
Can the below formula be put in VBA?
I use it in a table and sometimes the formula gets accidentally messed up which causes a problem
I also have to copy & paste the A? cell to hard code the number left after the date in C5 is entered.

I have the formula in A5 and as lines are added it changes by the date entered in C5 and increments by 1

=TEXT(C5,"YYYYMMDD")&TEXT(COUNTIFS(C$5:C5,">="&INT(C5),C$5:C5,"<"&INT(C5)+1),"-000")
 

Attachments

  • Tracking example.xlsx
    9.9 KB · Views: 2
You can certainly create a worksheet function that does the same thing. But depending on your goal, it may or may not satisfy you. You could write a function and then call the function from any cell in column A; if you name the function MyNumber, then the new formula might be "=MyNumber(5)", where the argument "5" tells the function which column to use. (The function can tell for itself what row.)

But you'd still have to copy that formula into any cell in A where you wanted to use it. If you never to have to copy the formula from one row to another in column A, off-hand I can't think of a way to do that. And after all, it's no more trouble to copy a long formula than a short one.

But maybe your only concern is that your formula is complicated, and every time you accidentally lose it you have to reinvent it. If that's the problem, then yes, writing a worksheet function would help you.

I take it your next question will be how to write that function?
 
Back
Top