Link to home
Start Free TrialLog in
Avatar of AL_XResearch
AL_XResearchFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Cell RowHeight and ColumnWidth BOTH register zero - how ?

I am working on a VBA solution where it checks the value of a hidden range of cells to see if that column has been flagged for processing. As I say the column is shown (say a column width of 18) but the row is hidden.

My issue is that on one test the 1st cell in the hidden range the RowHeight returns 0 AND the ColumnWidth returns 0. The worksheet does however show cells. My question is : how is this possible ? Normally these two measurements cannot both be zero or else there would be no cells shown (i.e. none of the columns or rows).

Can any expert suggest how this can happen ?

NOTE: I have made sure the worksheet is not protected
Avatar of etech0
etech0
Flag of United States of America image

Can you post the file so we can see the issue?
Avatar of AL_XResearch

ASKER

Etech0; unfortunately I cannot - I should have mentioned that initially.

I have worked many many  times in IT support so I know how limiting and irritating that it is but a) it is part of a multiple workbook solution that involves two books working together b) is extremely complicated and I would need to train you on that area of the system for you to understand what I am trying to do and to know which function to look in c) it is for a customer and so confidential d)

I have not, so far, been able to reproduce independently. With all that said it does happen consistently in the system.

I have tested, debuged and tracked down the issue to this root issue.
Avatar of [ fanpages ]
[ fanpages ]

Hi,

Why not just copy the single worksheet with the issue to a new workbook & copy'n'paste the data shown "As Values" so there are no links to any other worksheets/workbooks?

If the data is sensitive, simply replace each cell with a value with an "X" or something similar.

BFN,

fp.
Ok, I think I know what has been going on and it is in part my fault. I was unknowingly passing a range where both the row and the column that I was measureing were hidden (i.e. rowHeight = 0 and ColumnWidth = 0) - so that answers that.

The other part that is a little confusing is as follows and thus changes my question:

When you have a column with width of 9 and you hide the column in VBA the ColumnWidth reads as 0 but if you unhide the column using the excel interface the column width returns to 9. This behaviour causes a problem for my function that temporarily gives a hidden column (one with ColumnWidth = 0) a minimum width of 0.75 to allow searching on it's value and then restores it's previous column width (in this case 0) when finished.


How can I tell what columnwidth a cell was set to BEFORE it was hidden when it's columnWidth is set to 0 once hidden ? Excel appears to be able to do this but not via VBA ? Is this just one of Excel's oddities and limitations ?
ASKER CERTIFIED SOLUTION
Avatar of [ fanpages ]
[ fanpages ]

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fanpages: I am very sorry to read your post, I had hoped someone would come back and tell me I had missed something all these years. Your suggestion is just what I had been writing before I read your post (a version thereof anyhow). I am storing the column width for the key columns in a hidden row when the workbook is opened. I can the apply the correct width whenever I show those cells again.

Does anyone else have another suggestion / insight ?
Is there really no property that stores the 'unhidden colwidth' ? That is a huge Excel omission.
You might like to try this workaround

Set cr = Range("D:D").EntireColumn
If cr.ColumnWidth = 0 Then
    cr.Hidden = False
        Debug.Print cr.ColumnWidth
    cr.Hidden = True
Else
    Debug.Print cr.ColumnWidth
End If
You may wish to enclose ssaqibh's "workaround" with the following two statements:

Application.ScreenUpdating = False

(ssaqibh's code)

Application.ScreenUpdating = True


This will ensure the person using the workbook does not see the column become visible, & then hidden again.
ssaqibh & fanpages: Thanks for your responses. I have already used both these concepts in the solution I discussed in my previous post. One of the main issues, apart from the incorrect ColumnWidth of zero as above, is that the range being used has a mixture of columns some hidden and some unhidden.

The final solution I came up with was to use 2 boolean arrays that store the hidden property of each cell's row and column, one array for the row index and one for the column. At the end of my function the code reads the array and re-applies the 'hidden' status.