User Input Box to add item to named list

bms66

New Member
Joined
Jan 18, 2014
Messages
2
Hi

I am looking for a macro that will pop up an input box so the user can add an item to a named range used in a drop down list. E.g. sheet one column A is populated via a named range called colours which has three items. If the user enters another colour (via and input box) in list box i need it to check it doesn't already exist and then add it to the list and increase the range for the list box.

Any help appreciated

Thank you

Mykal
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Not sure how to mark this as solved or edit to reflect the same. I've managed to figure this one out now

Sub Button1_Click()
Dim strName As String
Dim Result
Dim newEntry As Variant, rws As Long, adr As String


strName = InputBox(Prompt:="Add Additional Colour", _
Title:="ADD COLOUR", Default:="Enter Colour Here!")
If strName = "Enter Colour Here!" Or _
strName = vbNullString Then
Exit Sub
Else

On Error Resume Next
Result = WorksheetFunction.Match(strName, Range("Colours"), False)
If Err = 0 Then
MsgBox "The Colour you have entered already exists"
Else

newEntry = strName
rws = Range("Colours").Rows.Count
Range("Colours").Cells(1, 1).Offset(rws, _
0).Value = newEntry
With Range("Colours").Name
adr = .RefersTo
.Delete
End With
Range(adr).Resize(rws + 1, 1).Name = "Colours"
Err.Clear
End If
On Error GoTo 0
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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