Sub FirstName()
'
' Macro2 Macro
'
Cells.AutoFilter
Range("A1").Select
Set Rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, Rng, , xlYes)
tbl.Name = "lTable"
tbl.TableStyle = "TableStyleLight8"
Range("A1").Select
currentColumn = 1
While currentColumn <= ActiveSheet.UsedRange.Columns.Count
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
keepColumn = False
If columnHeading = "Employee Name" Then keepColumn = True
If columnHeading = "Space #" Then keepColumn = True
If keepColumn Then
currentColumn = currentColumn + 1
Else
ActiveSheet.Columns(currentColumn).Delete
End If
If (ActiveSheet.UsedRange.Address = "$A$1") And (ActiveSheet.Range("$A$1").Text = "") Then Exit Sub
Wend
arrColOrder = Array("Employee Name", "Space#")
counter = 1
Application.ScreenUpdating = False
For ndx = LBound(arrColOrder) To UBound(arrColOrder)
Set Found = Rows("1:1").Find(arrColOrder(ndx), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not Found Is Nothing Then
If Found.Column <> counter Then
Found.EntireColumn.Cut
Columns(counter).Insert Shift:=xlToRight
Application.CutCopyMode = False
End If
counter = counter + 1
End If
Next ndx
Application.ScreenUpdating = True
'
'Deletes the entire row within the selection if the ENTIRE row contains no data.
Range("lTable[Employee Name]").Select
Dim i As Long
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
ActiveSheet.Buttons.Add(321.75, 37.5, 120, 42.75).Select
Selection.OnAction = "LastName"
Selection.Characters.Text = "Last Name"
With Selection.Characters(Start:=1, Length:=9).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
ActiveSheet.Shapes.Range(Array("Button 2")).Select
With Selection
.Placement = xlFreeFloating
.PrintObject = False
End With
ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort.SortFields. _
Add Key:=Range("lTable[[#All],[Employee Name]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
sFName = Application.GetSaveAsFilename
If sFName <> "False" Then ActiveWorkbook.SaveAs sFName
End Sub