Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
s s is offline
external usenet poster
 
Posts: 36
Default Store values in Combo Box

Hi,

I am just wondering how could I store the values a user has inputed in the
combo box so that next time, the user run the macro again, he can click on
the combo box and find his last input in the drop-down list.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Store values in Combo Box

You don't say how the ComboBox is populated initially. But suppose
ComboBox1 is initially populated from a list in Sheet1!A1:An. If the
user adds a new item to ComboBox1, the following code will add the new
item to the list. DO NOT use RowSource in the Properties Window.

Private Sub UserForm_Activate()
Dim iEnd As Long
Dim rng As Range
iEnd = Sheets("Sheet1").Range("A1").End(xlDown).Row
Set rng = Sheets("Sheet1").Range("A1:A" & iEnd)
ComboBox1.RowSource = rng.Worksheet.Name & "!" & rng.Address
End Sub

Private Sub ComboBox1_Change()
Dim rng As Range
Set rng = Range(ComboBox1.RowSource)
If IsError(Application.Match(ComboBox1.Value, rng, 0)) = True _
And ComboBox1.Value < "" Then
Set rng = rng.Resize(rng.Rows.Count + 1, 1)
rng(rng.Rows.Count, 1) = ComboBox1.Value
ComboBox1.RowSource = rng.Worksheet.Name & "!" & rng.Address
End If
End Sub

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
s s is offline
external usenet poster
 
Posts: 36
Default Store values in Combo Box

But what if the combo box is in a user form?! Like this user form will pop up
everytime the user run the macro.

"merjet" wrote:

You don't say how the ComboBox is populated initially. But suppose
ComboBox1 is initially populated from a list in Sheet1!A1:An. If the
user adds a new item to ComboBox1, the following code will add the new
item to the list. DO NOT use RowSource in the Properties Window.

Private Sub UserForm_Activate()
Dim iEnd As Long
Dim rng As Range
iEnd = Sheets("Sheet1").Range("A1").End(xlDown).Row
Set rng = Sheets("Sheet1").Range("A1:A" & iEnd)
ComboBox1.RowSource = rng.Worksheet.Name & "!" & rng.Address
End Sub

Private Sub ComboBox1_Change()
Dim rng As Range
Set rng = Range(ComboBox1.RowSource)
If IsError(Application.Match(ComboBox1.Value, rng, 0)) = True _
And ComboBox1.Value < "" Then
Set rng = rng.Resize(rng.Rows.Count + 1, 1)
rng(rng.Rows.Count, 1) = ComboBox1.Value
ComboBox1.RowSource = rng.Worksheet.Name & "!" & rng.Address
End If
End Sub

Hth,
Merjet



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Store values in Combo Box

But what if the combo box is in a user form?! Like this user form will pop up
everytime the user run the macro.


That is what I assumed. See my 1st line of code.

Merjet


Reply
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
Store range of values in an array Trevor Shuttleworth Excel Programming 6 November 8th 06 06:37 AM
Need to store changing values from one cell Emmie Excel Discussion (Misc queries) 5 September 17th 06 08:10 PM
Listbox - Store values tjh Excel Programming 1 September 17th 05 12:37 AM
ReDim to store values so they are not used again hotherps[_16_] Excel Programming 0 February 18th 04 06:34 PM
update and store new high values jack[_5_] Excel Programming 0 July 10th 03 01:22 AM


All times are GMT +1. The time now is 12:46 PM.

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

About Us

"It's about Microsoft Excel"