Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2005, 08:28 AM
Authorized User
 
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default data binding a combobox

Hi,

I have managed to build myself a combobox using data from another worksheet as the source data. is it possible to sort the list in the combobox by name? i am thinking that as i am using a range as opposed to an array it isn't possible without first sorting the range - which is not appropriate. :(

Thanks

Patrick

Visit my site: http://www.drybonesuk.com
__________________
Visit my site: http://www.drybonesuk.com
 
Old November 16th, 2005, 08:17 AM
Authorized User
 
Join Date: Oct 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shattered Send a message via Yahoo to shattered
Default

you could just sort the range in code

    Range("Sample").Sort ("Sample")

where Sample is the range name

Sub TestSort()
    Range("Sample").Sort ("Sample")
    Dim myArray() As String
    ReDim myArray(1 To Range("Sample").Count)
    Dim iInc As Integer
    For Each myVal In Range("Sample")
        iInc = iInc + 1
        myArray(iInc) = myVal
    Next myVal
End Sub

example code picks up the range, sorts it and then puts it into an array (purely so you can watch the effect). As this is done in code it doesn't affect your original range but does give you something to output to your combo box

If for example your combo box is called cbDisplay..

Sub UpdateCombo()
    Range("Sample").Sort ("Sample")
    With Sheets("Sheet1").cbDisplay
        .Clear
        For Each myval In Range("Sample")
            .AddItem myval
        Next myval
    End With
End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
Binding a comboBox to update a listView Amethyst1984 VB How-To 2 February 28th, 2006 03:07 PM
Issue Binding to ComboBox. lam_lvl VB.NET 2002/2003 Basics 1 February 22nd, 2006 09:38 PM
binding combobox to sqlreader? drachx General .NET 6 October 14th, 2004 07:10 PM
ComboBox Data Binding bmains VB.NET 0 October 5th, 2004 02:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.