I’m trying to create a command button that will expand row height on activecell to a couple preset heights then when maximum height is reached it would then return to lowest setting. I first tried If then statements with no success, now I’m trying to use Case statements. Here’s what I have so far.
EDIT: Taking a cue from Hans' message, here is my code using 100 as the increment and 400 as the wrap-around point (and I agree with him about the MessageBox)...
Sub ChangeRowHeight()
If ActiveCell.RowHeight > 300 Then
ActiveCell.RowHeight = 100
Else
ActiveCell.RowHeight = ActiveCell.RowHeight + 100
End If
End Sub
I omitted the message boxes - they become irritating quickly.
Thank you Rick and Hans for these great options
Hans when I first tried using the If then statement I didn’t have much success but I forgot to include “>†as in your suggestion. Very cool thanks
Actually, mine does not work because the RowHeight does not start at 0 (like the variable I used in my test did). Come back to the thread a little later, though, as I am sure there is a simple one-liner available.
I was trying to add another element to this code that would first unhide a determined row then hide row when row reaches a certain size. The reason for this type of code is I’m planning on using this row to insert photos if so needed along with the use of another piece of code that will place photo in selected cell in this row at a predetermined height size of 100. If this present row height is full of photos and more room is needed then by selecting button once more the row would be adjusted + 100 to accommodate more photos, and of course even once more if so needed. If row is then not needed by selecting button one last time the row would then be hidden. I hope I explained this OK. Does this code look correct?
Private Sub CommandButton1_Click()
With ActiveSheet.Rows("7:7")
.Hidden = False
.Rows.Select
End With
If ActiveSheet.Rows("7:7").RowHeight > 300 Then
ActiveSheet.Rows("7:7").RowHeight = 100
Else
ActiveSheet.Rows("7:7").RowHeight = ActiveCell.RowHeight + 100
End If
If ActiveSheet.Rows("7:7").RowHeight = 100 Then
With ActiveSheet.Rows("7:7")
.RowHeight = 1
.Hidden = True
End With
End If
End Sub
Private Sub CommandButton1_Click()
With ActiveSheet.Rows("7:7")
If .RowHeight > 300 Then
.RowHeight = 0
Else
.RowHeight = .RowHeight + 100
End If
End With
End Sub