Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

FORM  Drop Down issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 26 Sep 2007 18:19 GMT
I am using the following code to populate a drop down on a FORM in Excel.

Public Sub PopulatePositions()
   Dim AllCells As Range, Cell As Range
   Dim item As Variant
   Set AllCells = Worksheets("Positions").Range("A2:A150")
On Error Resume Next
   For Each item In AllCells
       Successor.cboPositionID1.AddItem item
   Next item

As you can see I have set the range to be from A2 to A150 which assumes 148
records.

There is not currently 148 records (104) so I end up will a lot of empty
rows on the dropdown.
The number of records will be changing so it would be nice to get a current
count of rows on the sheet when the FORM "Initializes" and then only
populates that many rows on the FORM Drop down.

Any help here will be appreciated.

Thanks in advance
dave
JW - 26 Sep 2007 18:38 GMT
one way:
Dim bRow As Long
bRow=Cells(Rows.Count,"A").End(xlUp).Row
Set AllCells = Worksheets("Positions").Range("A2:A" & bRow)

> I am using the following code to populate a drop down on a FORM in Excel.
>
[quoted text clipped - 20 lines]
> Thanks in advance
> dave
Bob Phillips - 26 Sep 2007 18:40 GMT
Public Sub PopulatePositions()
   Dim AllCells As Range, Cell As Range
   Dim item As Variant
   With Worksheets("Positions")
       item = .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
       Me.cboPositionID1.List = item
   End With
End Sub

Signature

HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

>I am using the following code to populate a drop down on a FORM in Excel.
>
[quoted text clipped - 20 lines]
> Thanks in advance
> dave
Dave - 26 Sep 2007 19:56 GMT
Thanks to you both for the replies.
used Bob's and it worked like a charm

dave
>I am using the following code to populate a drop down on a FORM in Excel.
>
[quoted text clipped - 20 lines]
> Thanks in advance
> dave
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.