+ Reply to Thread
Results 1 to 4 of 4

Hiding column causes VBA code to behave not as expected

  1. #1
    Registered User
    Join Date
    03-16-2016
    Location
    Liverpool
    MS-Off Ver
    MS Office 2010
    Posts
    14

    Hiding column causes VBA code to behave not as expected

    Hi,

    Hoping for some help. I have some VBA code in excel (which was provided by dflak) as follows:

    Please Login or Register  to view this content.
    This code works exactly as I expect. However if I hide column 28 then the code does not behave as I expect. After stepping through I can see that after the hiding column 28 the value for
    Please Login or Register  to view this content.
    in the line
    Please Login or Register  to view this content.
    evaluates to having no value even though the cell does contain "TRUE".

    Does anyone know if hiding a column that is referenced in VBA can affect tghe way the code runs?

    Thanks
    Kam Patel

  2. #2
    Forum Contributor
    Join Date
    09-23-2007
    Location
    Melbourne, Australia
    Posts
    176

    Re: Hiding column causes VBA code to behave not as expected

    Hi kampatel

    The problem is you have used

    Please Login or Register  to view this content.
    This problem is corrected if you use

    Please Login or Register  to view this content.
    I believe this is so because .Text gets a formatted / read-only version of the cell value. If the cell is not visible maybe that
    visual formatting is not there and thus there may not be enough information to reproduce the value in that cell.

    Feel free to correct me on that, anyone, but that's my understanding.

    Anyway, the above will fix your problem.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Hiding column causes VBA code to behave not as expected

    danny2000 is on the right track, but there is one more thing to consider. The value in Cells(RowNum, 28) is not the text "TRUE". It is a Boolean value of True. There is a difference.

    This would be the syntax to test if the .Value is a boolean True (no quotes around True).
    If Cells(RowNum, 28).Value= True Then

    Alternatively, you could use this comparison and forego the True\False values in column 28.
    If Cells(RowNum, 26) = Cells(RowNum, 27) Then
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    03-16-2016
    Location
    Liverpool
    MS-Off Ver
    MS Office 2010
    Posts
    14

    Re: Hiding column causes VBA code to behave not as expected

    Guys,

    Thanks for your help to both. A combination of what you have both said has worked.

    Thanks Again
    Kam

+ 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] Hiding and un hiding columns using VBA code
    By Jes1397 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2015, 12:52 AM
  2. [SOLVED] Why does my code not work as expected?
    By EMyk08 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2015, 12:29 PM
  3. I need the code for hiding a column if a cell in that column has no date.
    By Martynoxon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2013, 11:17 AM
  4. Un-Hiding and Hiding Columns based on Drop-Down Values in a Column.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-30-2011, 09:24 AM
  5. Un-Hiding and Hiding Columns based on Drop-Down Values in a Column.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2011, 06:49 AM
  6. VBA code for hiding column
    By MbahGondrong in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 01-31-2009, 10:36 AM
  7. Replies: 2
    Last Post: 10-18-2005, 10:05 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