+ Reply to Thread
Results 1 to 10 of 10

Changing Formula to a VBA script

  1. #1
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Changing Formula to a VBA script

    I have a formula that reads:

    =IFERROR(IF(A6<>"",TEXT(A6-DATE(YEAR(A6),1,0),"000")&"-"&TEXT(COUNTIF(A$2:A6,A6),"000"),""),0)

    If i multiply this formula in row b all the way down to the last row, the excel sheet will slow down.


    Is there a way to make this formula a VBA script to negate that issue? Thanks!

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: Changing Formula to a VBA script

    To how many rows do you copy this formula ?

    Try: Run macro, select cell or range and then choose the appropriate option:
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Changing Formula to a VBA script

    can you sort the list by date? or is it already sorted? (seems natural that it might be). If so maybe something like

    Please Login or Register  to view this content.
    sorting then running it then unsorting might also be fast, but hopefully not necessary.
    Last edited by scottiex; 01-10-2018 at 11:50 PM.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Changing Formula to a VBA script

    Your formula refers to A6, but I assume the formula is from row2.

    Change [b2] accordingly.
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Changing Formula to a VBA script

    Or you can try:

    Please Login or Register  to view this content.
    HTH,
    Maud

    dates.png
    Last edited by Maudibe; 01-11-2018 at 12:19 AM.

  6. #6
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Changing Formula to a VBA script

    The last one is really good. Thanks guys!

    I will test this to see if it lags and will get back to you soon...

    My testing is 4000 entries within the spreadsheet consisting of that code.

    Im getting a run mismatch with Maudibe's code.
    Run mismatch with Jindon's code.

    porucha's code works but is missing the - sign between the numbers.


    Sub Createcode()
    lastrowx = Cells(Rows.Count, "A").End(xlUp).Row
    a = Range("a1:a" & lastrowx).Value
    For i = 6 To lastrowx
    TYear = DateValue("1/1/" & Year(a(i, 1)))
    a(i, 1) = Format(a(i, 1) + 1 - TYear, "000")
    If a(i, 1) = a(i - 1, 1) Then
    j = j + 1
    Else
    j = 1
    End If
    a(i, 1) = a(i, 1) & "-" & Format(j, "000")
    Next i
    Range("b1:b" & lastrowx).Value = a
    End Sub
    Last edited by randy2012; 01-11-2018 at 02:18 AM. Reason: Giving constructive Feedback

  7. #7
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: Changing Formula to a VBA script

    Quote Originally Posted by randy2012 View Post
    ... code works but is missing the - sign between the numbers ...
    Formula is yours, not mine ... ... Your formula "likes me" ...
    Attached Images Attached Images

  8. #8
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Changing Formula to a VBA script

    It does work! Nice.

    Sadly the only thing i find difficult to do with Formula based algorithm is to refresh the sheet every year while transferring the old historical data (last year's entries) to another tab.

    Note to others: If you can fix your formula here and make it work better with less lag... then its a deal! I'll add to your reputation.
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Changing Formula to a VBA script

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Changing Formula to a VBA script

    Here u go,

    LOG_Rev.xlsm

    HTH,
    Maud

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. script to run the macro from Vb script with out opening the excel file
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2021, 03:33 AM
  2. calling the vb script from the shell script(unix platform)
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 06:21 AM
  3. [SOLVED] Changing CSE formula and changing Vlookup to Index Match
    By stockgoblin42 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-21-2013, 08:18 PM
  4. Integrating Mainframe emulator script with excel's vba script
    By Himanshu Mishra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 10:30 AM
  5. Create VBA script to short, dedicated button in excel for script?
    By realized in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2009, 11:54 PM
  6. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1