0

I am looking for a code to hide/Unhide last row with data but in a sequence using button.

I have created a table with a questions in top row and expecting 1 to 10 responses in the rows below. I will hide all 10 rows in a table and will ask responders to use button to unhide one row at a time for their answer.

I have tried following code but it unhide all rows whereas I need to unhide one row upon each click in sequence.

Dim startRow As Long: startRow = 1
Dim lastRow  As Long: lastRow = ActiveSheet.UsedRange.Rows.Count

ActiveSheet.Rows(startRow & ":" & lastRow).Hidden = False

I hope will get some good responses from the community with thanks in advance.

1 Answer 1

0

If you want to unhide one row at a time you can't use a range from startRow to lastRow, right? That will always unhide all rows from start row to last row.

If your intention is to unhide one row with each time the button is clicked, try this macro on the button. It will ignore rows that are already unhidden and unhide the first hidden row starting from the top, then end.

Sub test()
Dim startRow As Long: startRow = 1
Dim lastRow  As Long: lastRow = ActiveSheet.UsedRange.Rows.Count

Do While startRow < lastRow + 1
    If ActiveSheet.Rows(startRow & ":" & startRow).Hidden = True Then
        ActiveSheet.Rows(startRow & ":" & startRow).Hidden = False
        startRow = lastRow + 1
    End If
    startRow = startRow + 1
Loop


End Sub

Another, non-VBA approach would be to keep the rows visible and use formatting to hide the text. Then you can enter a trigger value into a cell that is checked by a conditional formatting rule and the value will be formatted to show. That way you can select any order to unhide answers.

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Teylyn! It is awesome. This code has worked for me perfectly as I wanted. I am using this code with form button that perform two actions: 1) Open new form for data entry; 2) Unhide new row set to record data upon submission. Actually I have multiple tables and wanted to use this approach to avoid issues with destination cell linkages by adding new row in my file with coding so am using hiding action to deal with it. But thank you so much for your great help!
Glad to help. Could you please mark the answer as explained in the Tour, so others can find it more easily.
Yes done but it shows that people with less than 15 reputation can mark but it is not available publicly. I will visit this answer back again and mark it once I reach to that score. This was my first ever post in this forum. Thanks Again!
If you ask the question you can mark the answer. You need reputation only to upvote, not to mark the answer. The two are different. Watch the Tour again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.