+ Reply to Thread
Results 1 to 15 of 15

Convert Hex values to Binary

  1. #1
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Convert Hex values to Binary

    Good afternoon,

    I have a Excel-file with Hex decimals. I want to convert these to Binary. I found some VBA code that looks like:
    Please Login or Register  to view this content.
    The Hex decimals starts in cell A1. How can I insert the 'strBytes' in the code link to a cell or column?

    It will looks like: strBytes = "Range.Select ("A1:A47")". Is this possible?

    Already thanks.
    Last edited by Schiavoni; 06-16-2020 at 08:41 AM.

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

    Re: Convert Hex values to Binary

    What are some typical entries in A1? What form of hex decimals are you using? e.g. is there a preceding $, is there a space between each 4th digit. Is each entry 8 digits long?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

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

    Re: Convert Hex values to Binary

    Have you looked at the HEX2BIN function?

  4. #4
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Re: Convert Hex values to Binary

    Example:
    I have the following code in cell A1:
    Please Login or Register  to view this content.
    When I fill in this code in VBA for 'strBytes', the outcome of the .bin file is:
    Please Login or Register  to view this content.
    This is what I want the file will look like, but then I want select some range in Excel to get the 'strBytes' code from.

    I have looked at HEX2BIN, but this isn't where I'm looking for. I want to open the extracted file from the VBA code in HexEdit to see the code from cell A1.
    Last edited by Schiavoni; 06-16-2020 at 10:38 AM.

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

    Re: Convert Hex values to Binary

    You could use this UDF, with a formula like =HexToBin(A1)

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Convert Hex values to Binary

    Quote Originally Posted by Schiavoni View Post
    Example:
    I have the following code in cell A1:
    Please Login or Register  to view this content.
    When I fill in this code in VBA for 'strBytes', the outcome of the .bin file is:
    Please Login or Register  to view this content.
    HEX2Bin isn't the thing I'm looking for.
    Your Subject header rather belies that last statement.

    What results do you expect to see?

    In answer to your last question you could include a loop to build the string

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Convert Hex values to Binary

    It looks like you could skip strBytes altogether and just use:

    Please Login or Register  to view this content.
    then just amend the loop to refer to arrBytes(i, 1) rather than just arrBytes(i)
    Rory

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Convert Hex values to Binary

    Quote Originally Posted by rorya View Post
    It looks like you could skip strBytes altogether and just use:
    Indeed....even better

  9. #9
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19

    Re: Convert Hex values to Binary

    Thanks for the help so far! I'm trying to getting right the code, but get some errors.

    With this code I get these errors: Subscript out of range (Error 9) and Type mismatch (Error 13)
    Please Login or Register  to view this content.
    With this code i get this error: Permission denied (Error 70). I don't know where to place arrBytes(i, 1)
    Please Login or Register  to view this content.
    I think that I do something wrong. When changing the original script to: strBytes = Cells(1, 1), Excel only converting Cell A1. When trying to change to Cells(1, 2) or something, only A1 is being convert.

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Convert Hex values to Binary

    As I mentioned, if you populate the array from a range, you need to alter the code in the loop too, since it's a 2d array:

    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Convert Hex values to Binary

    Quote Originally Posted by Schiavoni View Post
    I think that I do something wrong. When changing the original script to: strBytes = Cells(1, 1), Excel only converting Cell A1. When trying to change to Cells(1, 2) or something, only A1 is being convert.
    Try this
    Please Login or Register  to view this content.
    Or this
    Please Login or Register  to view this content.

  12. #12
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Convert Hex values to Binary

    Does each cell in A1:A47 contain a string like "F3 A1 02 00 04 00 8D 24 44 C3 8C 03 83 49 26 92 B5", or is it one hex char per cell?

  13. #13
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19
    Quote Originally Posted by huuthang_bd View Post
    Try this
    Please Login or Register  to view this content.
    This code is working. Thanks!

    Now I have in column A the merged Hexcodes. Is it possible to change the range to: A1:BL46 and A47:D47 together?

    In this range each cell contains a hex code with 2 characters.
    Last edited by Schiavoni; 06-17-2020 at 09:30 AM.

  14. #14
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Convert Hex values to Binary

    You can change the range if you want.
    Please Login or Register  to view this content.
    ❖ Please mark your thread is SOLVED if there has been offered a solution that works fine for you.

    ❖ If you like solutions provided by anyone, feel free to add reputation by clicking on ✶ Add Reputation bottom left of their posts.

  15. #15
    Registered User
    Join Date
    06-15-2020
    Location
    Eindhoven
    MS-Off Ver
    2016
    Posts
    19
    Thank you. The script is working now.

+ 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. Convert to Binary
    By Dhelp in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-26-2016, 01:42 AM
  2. [SOLVED] Convert Binary to Octal
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-06-2015, 11:59 AM
  3. Convert Hex to Binary formula
    By EddieK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 02:35 PM
  4. How to convert binary to date/time
    By snb in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-17-2010, 12:34 AM
  5. Convert word to binary
    By elbertvillarreal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2010, 06:09 PM
  6. [SOLVED] Convert Binary to Hex
    By Chipmunk in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2009, 06:02 AM
  7. [SOLVED] Convert SpreadsheetML to binary .xls
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-17-2006, 01:50 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