Hi
Put this code in the userform module.
Code:
Option Base 1
Private Sub CommandButton1_Click()
Dim IdxShtName As String
Dim ShtName As String
Dim ShtNew As Worksheet
Dim rngHLink As Range
Dim shpHLink As Shape
Dim blnHLink As Boolean
Dim ColCount As Long
Dim ShtCount As Long
Dim r As Long
Dim c As Long
If Len(Me.TextBox1.Value) Then
IdxShtName = Trim(Me.TextBox1.Value)
On Error Resume Next
Set ShtNew = Worksheets(IdxShtName)
If Err.Number <> 0 Then
Set ShtNew = Worksheets.Add
ShtNew.Name = IdxShtName
End If
Err.Clear: On Error GoTo 0
blnHLink = Me.OptionButton1.Value
ColCount = Me.ComboBox1.List(Me.ComboBox1.ListIndex)
If blnHLink Then
ShtCount = Worksheets.Count
With ShtNew
r = 1
For i = 1 To ShtCount
ShtName = Worksheets(i).Name
If ShtName <> IdxShtName Then
c = c + 1
Set rngHLink = .Cells(r, c)
rngHLink.Hyperlinks.Add rngHLink, Address:="", SubAddress:="'" & ShtName & "'!A1", TextToDisplay:=ShtName
If c Mod ColCount = 0 Then
r = r + 1: c = 0
End If
End If
Next
End With
Else
ShtCount = Worksheets.Count
With ShtNew
.Shapes.SelectAll
Selection.Delete
With .Cells(1).Resize(ShtCount, ColCount)
Debug.Print .Address
.Rows.RowHeight = 24
.Columns.ColumnWidth = 12
End With
r = 1
For i = 1 To ShtCount
ShtName = Worksheets(i).Name
If ShtName <> IdxShtName Then
c = c + 1
Set rngHLink = .Cells(r, c)
Set shpHLink = .Shapes.AddShape(5, rngHLink.Left + 2, rngHLink.Top + 2, rngHLink.Width - 4, rngHLink.Height - 4)
shpHLink.TextFrame2.TextRange.Text = ShtName
.Hyperlinks.Add shpHLink, Address:="", SubAddress:="'" & ShtName & "'!A1", TextToDisplay:=ShtName
If c Mod ColCount = 0 Then
r = r + 1: c = 0
End If
End If
Next
End With
End If
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
Dim c(10) As Long
For i = 1 To 10: c(i) = i: Next
With Me.ComboBox1
.Style = fmStyleDropDownList
.List = c
.ListIndex = 0
End With
Me.OptionButton1.Value = True
End Sub
Bookmarks