Announcement

Collapse
No announcement yet.

Syntax for VBA combo box

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Syntax for VBA combo box



    Hi guys,
    I have worked out the syntax for populating a combo box with a list from the same worksheet, how do I have to change the syntax if the list is on a different sheet in the same workbook.
    I really appreciate any help I can get with this one.
    Thanks
    Trac

  • #2
    Re: Syntax for VBA combo box

    Post your code. I will modify it when I see it.
    Eternity is a terrible thought. I mean, where's it going to end??

    Comment


    • #3
      Re: Syntax for VBA combo box "code for fengore"

      Hi fengore,
      here is the code
      Code:
      Private Sub UserForm_Initialize()
          Dim wscell As Range
          For each wscell In Range("A2:A6")
               cboname.AddItem (wscell.Value)
          Next
      End Sub
      I know I've got to put a reference to worksheet 1 in there somewhere, but just can't work out where and how!!!
      Regs & Thanx

      Comment


      • #4
        Re: Syntax for VBA combo box "code for fengore"

        Code:
         
        Private Sub UserForm_Initialize() 
            Dim wscell As Range 
            For Each wscell In Worksheets("Sheet1").Range("A2:A6") 
                cboname.AddItem (wscell.Value) 
            Next 
        End Sub
        Boo!

        Comment


        • #5
          Re: Syntax for VBA combo box

          Norie & Fengore,

          Thanks so much. I'll give it a go at lunchtime.
          Appreciate the really quick responses.
          Thanx
          Trac

          Comment


          • #6
            Re: Syntax for VBA combo box

            Rats. You go, brush your teeth, throw a load of laundry in, and here I am, too late.

            here is a slight tweak.

            Code:
            Private Sub UserForm_Initialize() 
            
                Dim wscell As Range
                Set w = Worksheets("Sheet1")
                For Each wscell In w.Range("A2:A6")
                    cboname.AddItem (wscell.Value) 
                Next 
            End Sub
            Last edited by fengore; November 8th, 2005, 08:17.
            Eternity is a terrible thought. I mean, where's it going to end??

            Comment


            • #7
              Re: Syntax for VBA combo box

              Fengore

              Sorry, I was just about to dive out the door, so thought why not.

              I also had another idea. Why bother using the AddItem method?
              Code:
              Private Sub UserForm_Initialize() 
                  cboname.RowSource="'Sheet1'!A2:A6" 
              End Sub
              Boo!

              Comment


              • #8


                Re: Syntax for VBA combo box

                Norie,
                Thanks, I was following a reasonably old book and having to dust off the cobwebs in my own brain to at least get as far as I did.
                Appreciate the assistance
                Trac

                Comment

                Working...
                X