+ Reply to Thread
Results 1 to 8 of 8

custom vba XOR function

  1. #1
    Registered User
    Join Date
    05-17-2018
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    5

    custom vba XOR function

    Hello everyone.
    I need to make a program in vba that calculates XOR. So 2 arguments - the 2 cells with binary numbers. The outcome of the function for example for cells (1010,1100) will be 0110 . When the characters are the same 1-1 and 0-0 the outcome is 0 and when they are different 1-0 0-1 the outcome is 1.
    Thanks guys.

    PS.: are here any Slovaks or Czechs?
    Last edited by plazmatv; 05-17-2018 at 03:42 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: Custom vba function help

    plazmatv,

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    After that, I have a question... are the 2 arguments always the same length?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    05-17-2018
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    5

    Re: Custom vba function help

    yes they are the same lengths and only binary numbers will be written in there.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,802

    Re: custom vba XOR function

    Your profile says that you have 2016. Is there a reason (like backward compatibility) that you don't want to use the built in XOR() function? https://support.office.com/en-us/art...2-0533bba14f37
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: custom vba XOR function

    This code will work with binaries even if not the same length just in case (by padding the left of the shorter binary with 0's)... but check MrShorty's reply... simpler solution.

    Please Login or Register  to view this content.
    P.S. Thanks for fixing the title

  6. #6
    Registered User
    Join Date
    05-17-2018
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    5

    Re: custom vba XOR function

    because the built in XOR gives me TRUE or False and i need numbers

  7. #7
    Registered User
    Join Date
    05-17-2018
    Location
    Slovakia
    MS-Off Ver
    2016
    Posts
    5

    Re: custom vba XOR function

    Thank you really much!

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,802

    Re: custom vba XOR function

    I looked a little closer, and I see what you mean.

    I checked Wikipedia and they claim that XOR is equivalent to addition without carry. If you have any interest in sticking with built in functions, it looks like something like =RIGHT(DEC2BIN(SUM(BIN2DEC(first number),BIN2DEC(second number))),4) should do the same thing.

+ 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] Usage of standard functions into custom function (or user defined function)
    By tusharb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2016, 12:43 AM
  2. Replies: 0
    Last Post: 11-20-2015, 12:34 PM
  3. VBA code for custom function that returns detail results of array function
    By onechipshot in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2015, 06:30 PM
  4. [SOLVED] Custom Function kicking out mid-function
    By JasonLeisemann in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-30-2013, 09:04 AM
  5. Replies: 1
    Last Post: 04-02-2006, 10:50 AM
  6. Custom Function: Detecting the cell the function is used in
    By g-boy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2005, 02:05 PM
  7. Emulate Index/Match combo function w/ VBA custom function
    By Spencer Hutton in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-02-2005, 01:06 PM

Tags for this Thread

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