I'm trying to float a button at the bottom of an Excel table

Joined
Aug 3, 2021
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
I have a table that I've created buttons to filter by current week, current month, and to clear all filters. The table can get very long, and I have information at the top that will push the table too far down the page if I freeze rows to always show buttons. I'm trying to create a button that always floats at the bottom of my table. I found code to float a button based on my selected cell, and that works great, but if I select a cell anywhere in the table, the button follows. I just want it to stay at the bottom. I also get a run-time error '1004': Application-defined or object-defined error if I select anything other than a single cell.

My goals:
  • always have the button float below the bottom left corner of the unfiltered rows of my table
  • moves with the table based on the filtered options
  • down when I add a row(s) to the table
  • doesn't error out if I select something like an entire row or column
Current code is below:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo 0
    With ActiveSheet.Shapes("Rectangle: Rounded Corners 10")
    .Top = Target.Offset(2, 0).Top
        .Left = Target.Offset(2, 0).Left
    End With
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Catch your insert, delete and filter in your worksheet events then run this:

VBA Code:
Public Sub AlignTableButtons()
    Dim osh As Shape
    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim lPos As Double ' not sure how big your table is
    Dim lastRow As ListRow
    
    Set ws = ActiveSheet  ' change to the name of your sheet
    Set tbl = ws.ListObjects("tblUser")
    Set osh = ws.Shapes("btnGroup")
    Set lastRow = tbl.ListRows(tbl.ListRows.Count)
    
    Application.ScreenUpdating = False
    
    lPos = lastRow.Range.Left
    
    With osh
        .Left = lPos
        .Top = lastRow.Range.Top + osh.Height + 2
    End With
    
    Application.ScreenUpdating = True

    Set tbl = Nothing
    Set osh = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top