View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
FSt1 FSt1 is offline
external usenet poster
 
Posts: 3,942
Default using rowsource to fill a combobox

hi
you are setting the combo box rowsource correctly. i think its the last row
that is giving you problems. replace the find with this...
lngLastRow= Cells(Rows.Count, "b").End(xlUp).Row
and you could say...
ComboBox2.RowSource = ws.Range("A1:B" & lngLastRow)
thus eliminating the need for rng.....less typing....easier to read and
understand later.

regards
FSt1

"Excel-Programming" wrote:

I changed this procedure to remove the "for each" to fill the combo
box and tried using the row source as a value. I changed the column
count to 2 and the bound column to 2. The reason is I need the A and
B columns in the range not just the A column.

The change seems to work but on a sub-procedure it doesn't fill the
variable with the selected value so possibly the row source isn't
working? THANKS!
----
Sub UserForm_Initialize()

Dim lngLastRow As Long
Dim ws As Worksheet
Dim c As Range
Dim rng As Range

Set ws = ThisWorkbook.Worksheets("patients")
lngLastRow = Cells.Find(What:="*", After:=ws.Range("A1"),
SearchDirection:=xlPrevious).Row
Set rng = ws.Range("A1:B" & lngLastRow)

Me.ComboBox2.Clear
ComboBox2.ColumnCount = 2 ******
ComboBox2.RowSource = rng.Address ******
ComboBox2.BoundColumn = 2 *****
' For Each c In rng.Cells
' Me.ComboBox2.AddItem c.Value
' Next c

Me.ComboBox2.AddItem "All"
Me.ComboBox2.AddItem "Exit"

End Sub
---------

here is a line from the sub-procedure where it doesn't compile:

thanks again,