Userform Add variable into list in Alphabetical position

Paul1005

New Member
Joined
Dec 27, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I'm trying to create a Userform so i can input several peices of data into a reference sheet (£) and it will then insert into a list in the correct position Alphabetcially. For example if i wanted to add "Tesla" into the below list it should be added inbetween SmithDS & United Utilities.

SegroSGRO
79​
Smith DSSMDS
93​
United UtilitiesUU.
35​
Vistry GroupVTY
95​

I have a LOT of formaula that pull data from this sheet into various other sheets so i dont really want to add to the bottom then reorder as i dont know what the implications on the other sheets would be.

I can do this with a Input Box option but there are several Variables so its not that user friendly - the code that works is:-

Sub InsertCompany()
Dim sNewName As String
Dim sCoNo As String
Dim TCKR As String
Dim lPosition As Long
Dim rEmpList As Range

' Add new Company with Input Boxes

Sheets("£").Select

Set rEmpList = Sheets("£").Range("A:A")

sNewName = InputBox("Enter name of new Company")
sCoNo = InputBox("Enter Company #")
TCKR = InputBox("Enter TCKR reference")
L

On Error Resume Next
lPosition = Application.WorksheetFunction.Match(sNewName, rEmpList, 1)
On Error GoTo 0
Rows(lPosition + 1).Insert
Range("A" & lPosition + 1).Value = sNewName
Range("B" & lPosition + 1).Value = TCKR
Range("C" & lPosition + 1).Value = sCoNo

End Sub


Then i created a userform with same Variables above and tried to use the same code to insert the values entered into the userform fields but this just adds a blank row in Row1 - it doesnt add any of the text input and doesnt add the rown in the correct position alphabetically. I'm totally stumped, can anyone help me please and point out where i've gone wrong?

Many thanks
Paul
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I was trying to avoid adding it to the bottom and then sorting.
I've got a work around which is to save the Userform values to a temporary location then copy these values in using an extract of the working input message code before deleting the values in the temporary location - while it works its a little clunky and not that elegant of a solution.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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