Hi, I found this code somewhere a while ago to make it easier to select worksheets
This is useful in the event there are too many sheets and you have to scroll to get to the sheet you need.
DialogSheet is used which I haven't come across before.
Was wondering if rich text is possible with DialogSheet.
Or perhaps may have to create a custom userform?
This is useful in the event there are too many sheets and you have to scroll to get to the sheet you need.
DialogSheet is used which I haven't come across before.
Was wondering if rich text is possible with DialogSheet.
Or perhaps may have to create a custom userform?
VBA Code:
Sub pupup_to_select_sheet()
Dim i As Integer
Dim posn_from_top As Integer
Dim sheetCount As Integer
Dim my_dialog As DialogSheet
Dim currentSheet As Object
Dim visbile_count_Sht As Integer 'visible count of sheet
Dim btn_Width As Integer 'optionbutton width to show description
Dim No_of_Columns As Integer 'number of column of optionbutton on panel
Dim sheet_count As Long
Dim rwnum As Long
Dim ladj As Long, tadj As Long
'Add temporary dialog sheet
Set my_dialog = ActiveWorkbook.DialogSheets.Add
sheetCount = 0
posn_from_top = 20
btn_Width = 100
sheet_count = ActiveWorkbook.Sheets.Count
No_of_Columns = sheet_count / 10
visbile_count_Sht = 0
For i = 1 To sheet_count
Set currentSheet = ActiveWorkbook.Sheets(i)
If currentSheet.Visible = xlSheetVisible Then
If my_dialog.Name <> currentSheet.Name Then
visbile_count_Sht = visbile_count_Sht + 1
End If
End If
Next i
If (Int(visbile_count_Sht / No_of_Columns) + 2) * (No_of_Columns - 1) >= visbile_count_Sht Then No_of_Columns = No_of_Columns - 1
my_dialog.Visible = xlSheetHidden
For i = 1 To sheet_count
Set currentSheet = ActiveWorkbook.Sheets(i)
'Skip hidden sheets and a temporary dialog sheet
If currentSheet.Visible = xlSheetVisible Then
If my_dialog.Name <> currentSheet.Name Then
rwnum = Int(visbile_count_Sht / No_of_Columns) + 2
If sheetCount Mod rwnum = 0 And sheetCount <> 0 Then
ladj = ladj + btn_Width
tadj = tadj - 13 * rwnum
End If
sheetCount = sheetCount + 1
posn_from_top = posn_from_top + 13
With my_dialog.OptionButtons.Add(78 + ladj, posn_from_top + tadj, btn_Width, 10)
.Text = currentSheet.Name
.OnAction = "ActivateSheet"
End With
End If
End If
Next i
'Set dialog height, width, and caption
'seen by the user
With my_dialog.DialogFrame
.Height = Application.Max(68, ((rwnum + 2) * 13))
.Width = (No_of_Columns) * btn_Width
.Caption = "Select sheet"
End With
my_dialog.Buttons.Delete
'Display the dialog box
my_dialog.Show
'delete at the end
'Delete temporary dialog sheet (without a warning)
Application.DisplayAlerts = False
my_dialog.Delete
End Sub
Private Sub ActivateSheet()
Dim ob As Excel.OptionButton
On Error Resume Next
Set ob = ActiveWorkbook.DialogSheets(1).OptionButtons(Application.Caller)
ActiveWorkbook.Sheets(CStr(ob.Text)).Select
On Error GoTo 0
End Sub