EDIT:
This was happening because the cell was set to the button’s LinkedCell property. When I set that to null everything works fine (of course, I was using that property, but oh well).
Couldn’t find anything on this through Google…
I have a cell that contains a fair amount of text in a fairly narrow column. I would like to have a button used to expand/retract the height of the cell when it is pushed (you know, ‘Show’ and ‘Hide’). The thing is, whenever I set the RowHeight property of the cell, the cell’s value is set to TRUE or FALSE. Can someone enlighten me as to why this is?
BTW, I am using Excel 2003.
Private Sub ToggleButton1_Click() new_caption = ToggleButton1.Caption Dim height As Integer If new_caption = 'Show' Then new_caption = 'Hide' height = 125 Else new_caption = 'Show' height = ToggleButton1.height End If ToggleButton1.Caption = new_caption Range(ToggleButton1.LinkedCell).RowHeight = height End Sub
That works fine for me, although I’m using Office XP rather than 2003. Are you sure that’s the code (or only code) that’s running for that button?
It sets the height correctly but doesn’t change the contents of the cell at all.
I’ve tried this as both a macro driven by a keypress and a command button on the sheet without a problem.
UPDATE:
Based on your edit where you state that you’re using LinkedCell to find the cell from your button, I don’t think your using it properly. LinkedCell binds the value of the cell to the value of the control.
What’s happening when you press the button is that its value is being set to a boolean (possibly true when pressed then false when released, I don’t know for sure). Because this is linked to a cell, the cells value is also changing to the button value. You need to find a different way to ‘link’ the button to the cell.
My first thought would be to link it to cell B1 so that your values are in A1, A2, A3, … (let’s call them Ax) and your controls buttons are in (and linked to) Bx and don’t use Bx for anything else (the buttons will probably appear above them anyway).
Then in your VBA code, you can still set the row height of Bx (since it affects the whole row) and you won’t care what has been place in the B-column cell – the A-column cell value will be left untouched.
Or, if you are using column B for something, link it to ZZx (or IVx or whatever the rightmost column is in a row).