I'm creating a worksheet that has one column and one header for the column. There is a button that prompts an input box and creates a new row in the column for the inputted value. I am trying to create a procedure that sorts the column alphabetically after the input box value has been added as a new row however I can't seem to get it to work.
This is my current code:
Dim NewOwner As Variant
NewOwner = InputBox("Enter Owner Name", "Add New Owner")
Dim ownersht As Worksheet
Dim ownerLastRow As Long
Set ownersht = ThisWorkbook.Worksheets("Owners")
Set ownerLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Dim ownerRange As Range
Dim ownerkeycell As Range
Set ownerRange = Range(Cells(2, 1), Cells(ownerLastRow + 1, 1))
Set ownerkeycell = Cells(2, 1)
If NewOwner = vbOK Then
With ownersht
ownerRange.Sort Key1:=ownerkeycell, Order1:=xlAscending, Header:=xlYes
End With
End If
There is no error notification however the code just doesn't seem to work. Any help would be appreciated, thanks!
This is my current code:
Dim NewOwner As Variant
NewOwner = InputBox("Enter Owner Name", "Add New Owner")
Dim ownersht As Worksheet
Dim ownerLastRow As Long
Set ownersht = ThisWorkbook.Worksheets("Owners")
Set ownerLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Dim ownerRange As Range
Dim ownerkeycell As Range
Set ownerRange = Range(Cells(2, 1), Cells(ownerLastRow + 1, 1))
Set ownerkeycell = Cells(2, 1)
If NewOwner = vbOK Then
With ownersht
ownerRange.Sort Key1:=ownerkeycell, Order1:=xlAscending, Header:=xlYes
End With
End If
There is no error notification however the code just doesn't seem to work. Any help would be appreciated, thanks!