Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default FORM Drop Down issues

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default FORM Drop Down issues

one way:
Dim bRow As Long
bRow=Cells(Rows.Count,"A").End(xlUp).Row
Set AllCells = Worksheets("Positions").Range("A2:A" & bRow)

Dave wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default FORM Drop Down issues

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


--
HTH

Bob

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

"Dave" <dave@accessdatapros wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default FORM Drop Down issues

Thanks to you both for the replies.
used Bob's and it worked like a charm

dave
"Dave" <dave@accessdatapros wrote in message
...
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


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
Data Form has macro issues SIR Knight Excel Discussion (Misc queries) 2 December 12th 06 12:39 PM
User Form issues Barb Reinhardt Excel Programming 1 October 16th 06 04:19 PM
controlling a form drop down based on selection of another drop down flurry[_7_] Excel Programming 1 June 5th 06 04:31 PM
User Form Initialize Event Issues Randy[_10_] Excel Programming 3 December 4th 05 11:20 AM
Excel Form Issues...again :) BOHICA Excel Programming 3 June 29th 04 08:49 PM


All times are GMT +1. The time now is 08:21 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"