+ Reply to Thread
Results 1 to 9 of 9

Convert formula into code

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Convert formula into code

    Hello code experts
    I have this formula to be converted into code. I tried to compare a similar code and convert this formula but I am getting stuck at applying the "" in the right place.
    This is the formula
    =IF((COUNTIFS($B$2:$B2,$B2,$C$2:$C2,$C2,$G$2:$G2,">="&$G2-1,$G$2:$G2,"<="&$G2+1)+COUNTIFS($B$2:$B2,$B2,$C$2:$C2,$C2,$H$2:$H2,">="&$H2-1,$H$2:$H2,"<="&$H2+1))<=(COUNTIFS($B$2:$B$30000,IF($B2="BOOKS","PORTAL","BOOKS"),$C$2:$C$30000,$C2,$G$2:$G$30000,">="&$G2-1,$G$2:$G$30000,"<="&$G2+1)+COUNTIFS($B$2:$B$30000,IF($B2="BOOKS","PORTAL","BOOKS"),$C$2:$C$30000,$C2,$H$2:$H$30000,">="&$H2-1,$H$2:$H$30000,"<="&$H2+1)),"MATCHED","Not Found")
    and the code to be replaced is as below.
    Please note that the below code is running without error. It is only the formula in the code which needs to be changed.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,032

    Re: Convert formula into code

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Convert formula into code

    Thanks ByteMarks. I will check it out tonight and revert back.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,537

    Re: Convert formula into code

    For the future:
    Enter the formula in a cell
    Select the cell
    Tools, Macro, Record
    F2, Enter
    The converted formula will be in a module where you saved it.
    Experience trumps academics every day of the week and twice on Sunday.

  5. #5
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Convert formula into code

    Like this
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Convert formula into code

    Wow!! This is something new I never knew. Thanks Jolivanes. Next time I will post it like this. I followed your steps and pasted the macro. Hope it is correct.

  7. #7
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,032

    Re: Convert formula into code

    It's a good tip. Not keen on the R1C1 notation though.

  8. #8
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,147

    Re: Convert formula into code

    Quote Originally Posted by ByteMarks View Post
    Please Login or Register  to view this content.
    It works perfectly. Thank you very much ByteMarks.

  9. #9
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,032

    Re: Convert formula into code

    You're welcome.

+ 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. [SOLVED] Need help to convert formula into code and place it in the existing code.
    By RAJESH SHAH in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-18-2022, 03:31 PM
  2. [SOLVED] Need to convert one formula into code and add it to the existing code
    By RAJESH SHAH in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-03-2022, 04:23 PM
  3. convert Formula to VBA code...
    By gr8spot in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-15-2016, 03:32 AM
  4. Convert Cell Formula to Convert Text to VBA Code
    By PY_ in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-08-2014, 05:51 PM
  5. [SOLVED] convert formula to vba code
    By krazyhype19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2014, 07:25 AM
  6. Convert Formula to VBA code
    By mpb86 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2013, 10:16 AM
  7. [SOLVED] vb help, convert from formula to vb code..
    By Michael A in forum Excel General
    Replies: 1
    Last Post: 01-07-2006, 07:35 AM

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