Solved

Excel VBA combobox update problem

Posted on 2002-03-14
10
2,503 Views
Last Modified: 2009-03-19
have a form with a combobox list box that gets updated with the program. It's not...

The named range is updating properly, but the form won't... here's my bits of code:

Worksheets("1stontape").Names.Add Name:="firstlist", RefersToR1C1:="=R1C1:R" & maxrowlist + 1 & "C1"

thats for updating the name range..

the rowsource IS set to firstlist. If I manually check the range, it IS working... but my form usually don't display it.... if I play around w/it enough, I might get lucky, but...

thanks!
0
Comment
Question by:starl
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6867580
please note that there is an MSOffice Topic area, where  you should get more experts for that problem:
http://www.experts-exchange.com/jsp/qList.jsp?ta=msoffice

Now, how/when do you update your forms' combobox?

CHeers



0
 
LVL 8

Author Comment

by:starl
ID: 6868050
I know angel... but this is a VBA prob and there's no real section for VBA. Though there is some knowledge of VBA in Office I hoped to get more here.

... update the combobox... well, it reads the listing off a named range on a sheet.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6868732
Hi starl, you provided the update of the named range, but is the form loaded and updated also?

i mean is there also a load list procedure to get the values in the combobox? or is that done at design time

:O)Bruintje
0
 
LVL 8

Author Comment

by:starl
ID: 6869021
*sigh* my ignorance and delving into something I don't knwo 100% is showing...

I've created a form in the editor. There is code behind that form. The part I'm having problems with is a combobox. It gets its list from a "rowsource" which, in this case, is a dynamic named range. I have other comboboxes on the form, but they are static - they show the info no problem.

Even if I restart the program and there IS info in the range, the combobox will not necessarily reflect this.

shouldn't it at least work ALL THE TIME if I restart the program? I've either done something wrong or there's a bug/error somewhere.

btw, excel 2000
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6869637
Hi starl, ok i did this

-put a form in the editor
-a combox on it
-then used this code to fill the box

Private Sub UserForm_Initialize()
Dim i As Integer
  For i = 0 To 10
    ComboBox1.AddItem i * i, i
  Next i
End Sub

-instead of the values i used with i you can loop through the named range to fill the box

if you need any help on that just ask....

HTH:O)Bruintje
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 8

Author Comment

by:starl
ID: 6869656
ok.. the named range is "firstlist" and the size will vary with time... how to work with it??
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6869724
:O) i had already pulled the plug on excel

Private Sub UserForm_Initialize()
Dim i As Integer
  For i = 0 To Worksheets(1).Range("firstlist").Count - 1
    ComboBox1.AddItem Range("firstlist").Value(i + 1, 1), i
  Next i
End Sub

HTH:O)Bruintje
0
 
LVL 12

Accepted Solution

by:
roverm earned 100 total points
ID: 6869829
You are using the worksheet name where you should have used the workbook names list...:

ActiveWorkbook.Names.Add Name:="firstlist", RefersToR1C1:="='1stontape'R1C1:R" & maxrowlist + 1 & "C1"

Also:
(But I don't know if you already did that): Refresh the combo by using:

Combo.RowSource = "firstlist"

You must do this at Form activation.

D'Mzzl!
RoverM
0
 
LVL 8

Author Comment

by:starl
ID: 6870113
Ha! thanks rover - that fixed it.. I did wonder why the namedrange had that extra line in the excel list of definitions. THANK YOU!

and I WAS missing the refresh. the last piece of the puzzle - thank you.
0
 
LVL 12

Expert Comment

by:roverm
ID: 6870571
Thanks starl! Glad I could help!

D'Mzzl!
RoverM
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now