Expand rows based on cell value

ktclrk

New Member
Joined
Feb 11, 2019
Messages
3
I need a macro code which I can attach to a command button which will expand specific rows based on cell values.

My sheet has a series of questions. or each question, there are 4 possible answers in a drop down menu in column A.
If the answer has more than 4 characters in length, I need the rows immediately beneath to expand.
If the answer has less than 4 characters in length, I need the rows to stay hidden.
There is no answer with exactly 4 characters in length.

The range for this is from rows 6 to 276.

Any suggestions are HIGHLY appreciated for this!


EDIT:
It looks like some of my text didn't all get in to the original post...

For each question...
If the answer has more than 4 characters in length, I need the 3 rows immediately beneath...
 
Last edited by a moderator:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Need help with macros script to expand rows

I'm new to macros and need some help please.

I have the following attached to a command button which worked yesterday but isn't working today.
Private Sub CommandButton1_Click()​
Sub ExpandRows()​
Range("C7").Select​
If Len(C7) > 4 Then​
Rows("8:10").Select​
Selection.EntireRow.Hidden = False​
End If​
End Sub​

Any suggestions?
 
Upvote 0
Re: Need help with macros script to expand rows

I figured it out! If anyone is following... I took a different approach and it works like a charm :)

Private Sub CommandButton1_Click()


For a = 7 To 262


If Worksheets("Sheet 1").Cells(a, 1).Value = "Recommendation" Then


Worksheets("Sheet 1").Rows(a + 1).Hidden = False
Worksheets("Sheet 1").Rows(a + 2).Hidden = False
Worksheets("Sheet 1").Rows(a + 3).Hidden = False

End If

If Worksheets("Sheet 1").Cells(a, 1).Value = "Deficiency" Then


Worksheets("Sheet 1").Rows(a + 1).Hidden = False
Worksheets("Sheet 1").Rows(a + 2).Hidden = False
Worksheets("Sheet 1").Rows(a + 3).Hidden = False


End If


Next


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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