LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Getting input from combobox to update sheet


Hi John,

With the following code you need to initially name one cell only as
Cardholder. The code assumes this cell to be Cell A1 on worksheet Carddata.

As the names are added in the combo box, if not already existing, they are
added to the top of the list and the named range for the combo is redefined
with the expanded range.

The RowSource property for the combo needs to be set to Cardholder. (Can't
do this until after cell is named Cardholder.)

The MatchRequired property for the combo needs to be false.

Do a Find and Replace on the following code to change the sub name from
ComboBox1 to match the name of your combo box.

Private Sub ComboBox1_AfterUpdate()
Dim comboEntry As Variant
Dim rngTofind As Range
Dim lngRows As Long

'Save the Combo box entry to a variable
comboEntry = ComboBox1.Value

'Test if combo box entry exists in Rowsource
With Sheets("Carddata")
Set rngTofind = .Range("Cardholder") _
.Find(What:=comboEntry, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
End With

'If entry not found then add it to named range
If rngTofind Is Nothing Then
lngRows = ComboBox1.ListCount + 1

With Sheets("Carddata")
'Move existing Cardholder range down 1 cell
'to allow new entry to be at top of range.
.Range("Cardholder").Cut _
Destination:=.Range("A2")

'Redefine Cardholder range to include
'additional cell for new combo box entry.
.Range(.Cells(1, 1), _
.Cells(lngRows, 1)) _
.Name = "Cardholder"

'Populate the first cell in the named range
'with the new combo box entry.
.Cells(1, 1) = comboEntry
End With

'Update the Rowsource for the combo box
ComboBox1.RowSource = ("Carddata!Cardholder")
End If

End Sub


--
Regards,

OssieMac




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input from ComboBox Bill_Green Excel Programming 1 August 3rd 08 02:24 PM
Need to update a ComboBox when selecting a sheet [email protected] Excel Worksheet Functions 1 October 31st 07 02:23 PM
Combobox options based on the input of another combobox afmullane[_5_] Excel Programming 1 May 3rd 06 01:44 PM
ComboBox input Geoff[_12_] Excel Programming 6 July 20th 05 06:59 PM
Compare input from ComboBox stevem[_4_] Excel Programming 0 April 1st 04 07:42 PM


All times are GMT +1. The time now is 02:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"