Activecell.text on a Hidden Cell

SeaDub

New Member
Joined
Jun 21, 2011
Messages
2
Got a bit of a strange one.

Looping through a group of cells, and if the cell value is blank, I want to put a value in the cell (in this case, 0).

Heres the problem. When the cells are visible, it works fine. When the cells are hidden, the activecell.text is equal to "". If I run the code on the same cells when not hidden, the text is equal to the cell value (normally a number).

Code:
Sub RemoveBlanks()
    Range("A1").Select
    While ActiveCell.Row <= Range("C10").Row
        While ActiveCell.Column <= Range("C10").Column
            If ActiveCell.Text = "" Then
                    ActiveCell.Value = 0
            End If
            ActiveCell.Offset(0, 1).Activate
            colCounter = colCounter + 1
        Wend
        ActiveCell.Offset(0, 0 - colCounter).Activate
        colCounter = 0
        ActiveCell.Offset(1, 0).Activate
    Wend
End Sub

Also, I'm aware I could use a Goto Special blanks on this example, but in my application the range is a lot more complicated and I would not be able to do this.

Any thoughts on why excel cannot see hidden cells .text?

Any input would be greatly appreciated! Thanks so much.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Because the text to show is "" if the cell is hidden.

Perhaps if you replaced myCell.Text with Format(myCell.Value, myCell.NumberFormat).
 
Upvote 0
Do you actually need to use .Text instead of .Value for some reason?
(curiously, .Text seems to return the formatted value if the row is hidden, but "" if the column is hidden)
 
Upvote 0
Mike - Your solution of changing:

Code:
If ActiveCell.Text = "" Then

to

Code:
If Format(ActiveCell.Value, ActiveCell.NumberFormat) = "" Then

seems to work. Thanks so much for your help.

rorya - I was using .text instead of .value as I was getting errors on my calcs as sometimes my cell values are Strings, Numbers, even #VALUE. Who doesn't love a good #VALUE.

Thanks to both of you for your unbelievably fast help.
 
Upvote 0
If you are just trying to clean up your data types.

CStr(ActiveCell.Value) will always return a string, protecting against error values (e.g. #DIV/0)

Val(CStr(ActiveCell.Value)) will return a number, (non-numeral) strings and errors are treated as 0.
 
Upvote 0
If you have errors in your cells, then I think Mike's code will also give you an error. You are better off checking that separately first:
Code:
If IsError(Activecell.Value) then
  ' do whatever you want for errors
ElseIf Len(ActiveCell.value) = 0 Then
                    ActiveCell.Value = 0
End If
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,507
Members
452,194
Latest member
Lowie27

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top