Macro to create Sort buttons
Hi Jim
Thank you for replying. Apologies for not making myself clear.
The buttons are great but they are fixed in size - I was hoping to
fill the cell that the heading was in plus if that column was resized
the button too would resize. Here is my pathetic attempt...
Sub SetupOneTime()
'adds rectangle at top of each column
'code written by Dave Peterson 2005-10-22
'screwed around with by Jim Cone 2011-06-12
' so as to use buttons instead of rectangles.
Dim myRng As Range
Dim myCell As Range
Dim curWks As Worksheet
'Dim myRect As Shape
Dim btn As Button
Dim iCol As Integer
Dim iFilter As Integer
iCol = 7 'number of columns
iFilter = 14 'width of drop down arrow
Set curWks = ActiveSheet
With curWks
Set myRng = .Range("a1").Resize(1, iCol)
For Each myCell In myRng.Cells
With myCell
Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
Selection.AutoFilter
'Set myRect = .Parent.Shapes.AddFormControl(xlButtonControl, _
Top:=.Top, Height:=.Height, _
Width:=.Width - iFilter, Left:=.Left)
End With
myRect.OnAction = ThisWorkbook.Name & "!SortTable"
myRect.TextFrame.Characters.Text = myCell.Value2
Next myCell
End With
End Sub
|