+ Reply to Thread
Results 1 to 18 of 18

VBA Gets Empty Value from Not-Empy Value Cell

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    Sheffield
    MS-Off Ver
    Excel 2013
    Posts
    86

    VBA Gets Empty Value from Not-Empy Value Cell

    Hi,

    sounds really weird.
    Please see attachment.
    If I read the cell value troough VBA the variable aaa results Empty while it has a specific value (7AJF138.T250).
    The weird thing is that while aaa is Empty, if i I print it with the Msg Box, it shows the right value.

    How do I fix it?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    Please post the code in the thread. I can't see it on an iPad.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    the variable aaa results Empty
    Can you be more specific what you mean by this? When I use IsEmpty it returns False (see below). However, when I mouseover aaa during execution it just says

    aaa=

    That is very strange because if it were the null string or unassigned it would be

    aaa=""

    I checked the character string you are using and it is all just printable ASCII characters, no control characters. But it seems to be specific to your character string. When I put anything else in the same cell it works normally.

    Everything else in the code seems to be OK. I modified your code to diagnose:


    Please Login or Register  to view this content.
    and got these results, which indicate nothing unusual:
    Please Login or Register  to view this content.
    Then I tried removing one character at a time. These two caused no problems, but all the other ones still had the problem:

    7JF138.T250
    7AF138.T250

    So there is something about the specific character combination causing this.

    blank.jpg
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    06-19-2013
    Location
    Sheffield
    MS-Off Ver
    Excel 2013
    Posts
    86

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    You got exactly the problem.
    I can see it in the Immediate Window, I can even print it in a sheet.
    But I need to store it in array, which seems impossible.

    Any hint for a possible workaround?

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    I have not gotten far enough to look at the issue when assigning to an array, but I'll follow up.

    I have a suspicion this is a bug in Excel/VBA.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Talking Re: VBA Gets Empty Value from Not-Empy Value Cell


    Hi Jeff !

    It can not be a bug as a String variable can not be 'Empty' so just a bad logic not using an appropriate variable type
    like in this VBA beginner demonstration according to the empty active cell :

    PHP Code: 
    Sub Demo1()
        
    Dim S$, V
            S 
    ActiveCell.Value2
            V 
    ActiveCell.Value2
            Debug
    .Print IsEmpty(S), IsEmpty(V), ""
    End Sub 

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    Marc, I'm not sure what you are trying to demonstrate. The original question shows a text value from a cell assigned to a String variable. IsEmpty returns False, and Debug.Print shows the expected value. But the value cannot be seen in the debugger on mouseover of the variable, and it cannot be assigned to an array element. If you look at the screenshot I attached, in particular the mouseover pop-up

    aaa =

    that should not be possible with a String variable. The issue also correlates to the content of the text string. Only certain values cause this problem.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Gets Empty Value from Not-Empy Value Cell


    From VBA basics : a String variable never forever can ever be 'Empty' ‼

    So never use VBA function IsEmpty with a String variable, I'm clear enough ?

  9. #9
    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,911

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    I can see the value being assigned to the array.
    Rory

  10. #10
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    I can see it in the array...
    Attached Images Attached Images

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Gets Empty Value from Not-Empy Value Cell


    Hi Dangelor,

    your aaa variable is obviously Variant instead of String like in the initial VBA procedure, as yet demonstrated in post #6 …

  12. #12
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    The snap was taken directly from the workbook provided in post #1.

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Gets Empty Value from Not-Empy Value Cell


    Ok : on my side under Excel 2010 aaa does not contain the cell value but "item" ! And I can not select any other cell within the sheet,
    when I select another workbook after less than a second the active window comes back to the Test_Doesn_Get_Value workbook automatically,
    so weird ! So for some reason there is some glitch within this workbook …
    Attached Images Attached Images

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Gets Empty Value from Not-Empy Value Cell


    Information : I can select any cell before running the VBA procedure but not anymore after !
    The same after I closed the workbook and re-opened it …

    If I add any cell property like Value, Text or Value2 whatever,
    if I run the same VBA procedure with aaa as a String variable the value returned is "15" !
    With a come back as Variant sometimes aaa may return the correct cell value but sometimes it's still "15" …

    I tried with a brand new variable S : exactly the same behaviour …

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Gets Empty Value from Not-Empy Value Cell


    When I try to close the workbook I get a message if I want to save another one !
    Hoping there is no hidden virus within the post #1 workbook …

  16. #16
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    Just to rule out a file corruption I created a new file from scratch and typed in the content for the cell, and got the same result.

  17. #17
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Gets Empty Value from Not-Empy Value Cell

    Also, I had been focused on the variable aaa and did not even look at the array. I am getting the value correctly assigned to the array element, and the correct value in aaa, even though the mouseover for aaa doesn't look right. So the code runs as expected, it's just that the debugger has a hiccup.

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Gets Empty Value from Not-Empy Value Cell


    On my side, I got the same result too on another workbook but after rebooting the computer,
    entering the same value on a brand new workbook no issue, all works as usual !
    So the issue comes from the post #1 workbook …

+ 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. How to get rid of an empy line
    By lostsoul65 in forum Excel General
    Replies: 5
    Last Post: 01-10-2019, 02:01 PM
  2. Pop Up alert for 2 empy cells
    By TORAMIKI in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2014, 03:41 AM
  3. Delete row if empy
    By frank35 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-17-2013, 12:48 PM
  4. [SOLVED] Finding the first empy cell in a set range of cells
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2013, 04:39 PM
  5. [VBA] Open excel file and copy in last empy cell
    By forfiett in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 02:55 PM
  6. [SOLVED] Userform to add data into next empy
    By andywsw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 10:09 PM
  7. delete empy rows
    By Khalil Handal in forum Excel General
    Replies: 3
    Last Post: 04-13-2005, 05:06 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