Hi again,
Ok, see if the attached version of the workbook does what you need.
It uses the following code in the VBA CodeModule of the worksheet in question:
Option Explicit
'=========================================================================================
'=========================================================================================
Private Sub cmbPageNo_DropButtonClick()
Dim vaDropdownList As Variant
With Me.cmbPageNo
' If appropriate (i.e. if the dropdown list contains no items),
' populate the dropdown list of the Page No ComboBox
If .ListCount = 0 Then
vaDropdownList = gvaPageDetails()
.List = vaDropdownList
' Display only the Page No and Page Title in the dropdown list
.ColumnWidths = "20, 90, 0"
.ColumnCount = 3
.ListRows = 16
End If
End With
End Sub
'=========================================================================================
'=========================================================================================
Private Sub cmbPageNo_Change()
Dim iPageNo As Integer
With Me.cmbPageNo
' Proceed only if a value has been selected from the dropdown list
If .Value <> vbNullString Then
iPageNo = .ListIndex + 1
Call TogglePage(iPageNo:=iPageNo)
' Clear the currently-displayed value from the ComboBox - if this is not done,
' selecting that value again (to immediately re-toggle the worksheet) will not
' count as a Change event, and this routine will not be triggered
.ListIndex = -1
End If
End With
' Move the focus away from the ComboBox
ActiveCell.Activate
End Sub
and the following code in a standard VBA CodeModule:
Option Explicit
'=========================================================================================
'=========================================================================================
Const miINDEX__RANGE As Integer = 3
Const miNO_OF_PAGES As Integer = 7
'=========================================================================================
'=========================================================================================
Public Function gvaPageDetails() As Variant
Dim vaPageDetails As Variant
Dim wks As Worksheet
ReDim vaPageDetails(1 To miNO_OF_PAGES, 1 To 3)
' Page Numbers
vaPageDetails(1, 1) = Format(6, "00")
vaPageDetails(2, 1) = Format(9, "00")
vaPageDetails(3, 1) = Format(12, "00")
vaPageDetails(4, 1) = Format(17, "00")
vaPageDetails(5, 1) = Format(20, "00")
vaPageDetails(6, 1) = Format(21, "00")
vaPageDetails(7, 1) = Format(24, "00")
' Page Titles
vaPageDetails(1, 2) = "Names"
vaPageDetails(2, 2) = "Addresses"
vaPageDetails(3, 2) = "Departments"
vaPageDetails(4, 2) = "Divisions"
vaPageDetails(5, 2) = "Phone Nos"
vaPageDetails(6, 2) = "Cities"
vaPageDetails(7, 2) = "Budgets"
' Page Ranges
Set wks = ActiveSheet
With wks
Set vaPageDetails(1, miINDEX__RANGE) = .Range("101:120")
Set vaPageDetails(2, miINDEX__RANGE) = .Range("161:180")
Set vaPageDetails(3, miINDEX__RANGE) = .Range("221:240")
Set vaPageDetails(4, miINDEX__RANGE) = .Range("321:340")
Set vaPageDetails(5, miINDEX__RANGE) = .Range("381:400")
Set vaPageDetails(6, miINDEX__RANGE) = .Range("401:420")
Set vaPageDetails(7, miINDEX__RANGE) = .Range("461:480")
End With
gvaPageDetails = vaPageDetails
End Function
'=========================================================================================
'=========================================================================================
Public Sub TogglePage(iPageNo As Integer)
Dim vaPageDetails As Variant
Dim rPageRange As Range
vaPageDetails = gvaPageDetails()
Call ResetPageBreaksIfAppropriate(vaPageDetails:=vaPageDetails)
Set rPageRange = vaPageDetails(iPageNo, miINDEX__RANGE)
With rPageRange
.EntireRow.Hidden = Not .EntireRow.Hidden
If .EntireRow.Hidden = True Then
.Rows(1).EntireRow.PageBreak = xlPageBreakNone
Else: .Rows(1).EntireRow.PageBreak = xlPageBreakManual
End If
End With
End Sub
'=========================================================================================
'=========================================================================================
Private Sub ResetPageBreaksIfAppropriate(vaPageDetails As Variant)
Dim rPageRange As Range
Dim iPageNo As Integer
vaPageDetails = gvaPageDetails()
For iPageNo = 1 To UBound(vaPageDetails, 1)
Set rPageRange = vaPageDetails(iPageNo, miINDEX__RANGE)
With rPageRange.Rows(1).EntireRow
If .Hidden = False Then
.PageBreak = xlPageBreakManual
End If
End With
Next iPageNo
End Sub
The highlighted values may be altered to suit your requirements.
Hope this helps - as before, please let me know how you get on.
Regards,
Greg M
Bookmarks