+ Reply to Thread
Results 1 to 16 of 16

Convert Boolean Array to an Integer Array

  1. #1
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Convert Boolean Array to an Integer Array

    Hi, wondering is there a VBA equivalent of --() in excel that turns trues and falses to 1's and 0's?
    Last edited by cmore; 06-21-2014 at 09:24 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VBA Equivalent of -- or 2 negatives

    True * -1 = 1
    False * -1 = 0
    Ben Van Johnson

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA Equivalent of -- or 2 negatives

    Do you mean like this:

    Please Login or Register  to view this content.
    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA Equivalent of -- or 2 negatives

    The conversion functions CLng, CDbl etc wil convert from boolean.
    Last edited by mikerickson; 06-21-2014 at 03:47 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: VBA Equivalent of -- or 2 negatives

    Thanks Guys, but I realized I'm unclear, I guess the question should be how do you convert boolean array to an integer array?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Convert Boolean Array to an Integer Array

    How are you creating the boolean array?
    If posting code please use code tags, see here.

  7. #7
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Convert Boolean Array to an Integer Array

    Norie, how's it going boss. I'm taking an array from a range and loading into an array and then using Application.Index(Bigarray, 0, 1) to get the subarray. A while ago you came up with doing this

    Please Login or Register  to view this content.
    I think the only limitation with this was the character maximum for Evaluate, which was an issue for my other application but works for the one I'm currently working on. I was just wondering if there's anything else more direct, as the other convention of pushing to a named range, then pushing back to vba and deleting that name is a bit painful
    Last edited by cmore; 06-21-2014 at 01:03 PM.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Convert Boolean Array to an Integer Array

    Are you sure that's for converting boolean to integer?

    When I try it with a boolean array populated via code it doesn't work, thought it will work if the boolean values are actually strings, ie 'True'/'False'.

    Can you give more details on what you are actually trying to do?

  9. #9
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Convert Boolean Array to an Integer Array

    Yeah, it's definitely boolean array turned to string using join, only thing is that I transpose it to get to a 1-D array first result: "True,True,True,True,True".

    My Problem is manipulating data against multiple conditions quickly and without having to write tons of line of code. I am finding myself basically doing this task a number of times one way or the other and just hoping to figure out an efficient way of doing things.

    Right now I basically load a set of data into an array work in it in VBA push it to a Named Range push it back to VBA work on it a little more and then push it back to excel. This keeps the file relatively light, and minimizes some user input errors, but just hoping for a more direct solution

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Can you post the code you are using to get/populate the boolean array?

  11. #11
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Convert Boolean Array to an Integer Array

    Yessir

    Please Login or Register  to view this content.

  12. #12
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Convert Boolean Array to an Integer Array

    Perhaps something like this will work for you

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Convert Boolean Array to an Integer Array

    Thanks mikerickson, the only thing is in most cases I try to only reference the worksheet once. So I'll load a data set into an array, and then will manipulate the data in vba before putting it back into the sheet

  14. #14
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Convert Boolean Array to an Integer Array

    I'm suggesting that you reference the worksheet cells only once. Get both the boolean and the numeric array with one range reference.

  15. #15
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Convert Boolean Array to an Integer Array

    Gotchya, I see what you're saying, problem is the range that I initially pull in has varying data types not just boolean. So for instance I'll grab all the data from a work sheet and then just need to summarize it in different ways based on other inputs or limit inputs in other areas in the workbook.

  16. #16
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: Convert Boolean Array to an Integer Array

    So right now it really looks the take the VBA generated Boolean array and pushing it to a named range and then evaluating that named range into the VBA array and then deleting the named range is the most dynamic (non-looping) way of conversion. The Join * Evaluate mechanism fails when you have just one element, so you'd have to write a condition. but if I knew there would always be >1 Join * Evaluate seems pretty awesome

+ 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. Getting negatives (-1) in the out put
    By kasi.maddula in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-30-2014, 06:21 AM
  2. Sum Negatives into next Positive
    By ScooterNM5 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-05-2010, 07:01 AM
  3. formula to allow only negatives
    By Jack 42 in forum Excel General
    Replies: 8
    Last Post: 05-04-2007, 01:58 PM
  4. [SOLVED] Positives and Negatives
    By Niagera College Student in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-20-2005, 06:05 PM
  5. [SOLVED] No negatives
    By PCOR in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2005, 03:06 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