Toggle for Macro

J

JAD

I have a worksheet that contains (50) identical estimates with one following
the next down the spreadsheet. Each estimate is (24) rows long. AT the top of
the worksheet is a single summary that shows the cost value for each of the
detailed estimates below. I also use the summary to navigate to each detail
estimate by hyperlinking. If I show all (50) estimates, I would have a
minimum length of 50 x 24 rows or 1200 total rows long. Instead of showing
all (50) estimates, I want to only show the estimates the user will be using
and hide all others. Using the top summary, I was going to add a position a
toggle next to each estimate summary row that when pressed will unhide the
estimate the user will now enter data into. If pressed again, the estimate
will go back to a hidden state. So, if TRUE the estimate is unhidden. If
FALSE, the estimate is hidden. Question (finally): What would the VB
statement look like to both hide and unhide a group of (24) rows per
estimate? Assume the worksheet is shown initially with all (50) estimates in
the hide status. Only when the toggle button is first clicked on does the
particular estimate unhide. Any help would be greatly appreciated. Thank You,
JAD
 
O

Office_Novice

Option Explicit
Sub CommandButton_Click
Dim ARange As Range
Set ARange = Range("A1:A24")
If ARange.EntireRow.Hidden = True Then
ARange.EntireRow.Hidden = False
ElseIf ARange.EntireRow.Hidden = False Then
ARange.EntireRow.Hidden = True
End If
End Sub
 
O

Office_Novice

Or for a Toggle Button

Private Sub ToggleButton1_Click()
Dim ARange As Range
Set ARange = Range("A1:A24")
If ToggleButton1 = False Then
ARange.EntireRow.Hidden = False
ToggleButton1.Caption = "Range Visible"
ElseIf ToggleButton1 = True Then
ARange.EntireRow.Hidden = True
ToggleButton1.Caption = "Range Hidden"
End If
End Sub
 
R

Rick Rothstein \(MVP - VB\)

This code should do the same thing...

Sub CommandButton_Click()
With Range("A1:A24")
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
End Sub

Rick
 
R

Rick Rothstein \(MVP - VB\)

In the same vain as my response to your other posting in this thread, this
code should do the same thing...

Private Sub ToggleButton1_Click()
Range("A1:A24").EntireRow.Hidden = ToggleButton1.Value
End Sub

Rick
 
R

Rick Rothstein \(MVP - VB\)

Actually, for only two references, we can probably drop the With/EndWith
housing...

Sub CommandButton_Click()
Range("A1:A24").EntireRow.Hidden = Not Range("A1:A24").EntireRow.Hidden
End Sub

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top