Thread: ListBox problem
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default ListBox problem

Hi Patrick,

Set rng = Cells(ActiveCell.Row, 1)


sets the rng variable to the column A cell of the active row.

The expression:

rng(1, 0).Value = ListBox1.List(ListBox1.ListIndex, 0)


is equivalent to:

rng.Offset(0,-1).Value = ListBox1.List(ListBox1.ListIndex, 0)

and it it will therefore fail because ot is not possible it is not possible
to reference in a column before column A.

rng(1, 1).Value = ListBox1.List(ListBox1.ListIndex, 7)


If the listbox has 7 columns, the last column will be column 6, as the index
is zero-based index

---
Regards,
Norman


"Patrick Simonds" wrote in message
...
Can anyone tell me why the following code will not place the contents of
column 1 in the active cell, and column 2 in the cell to the right of the
active cell? The ListBox has 7 columns.



Private Sub CommandButton3_Click()

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 0).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 1).Value = ListBox1.List(ListBox1.ListIndex, 7)

Unload EmployeeList

End Sub