0
votes

Tried using this coding but no luck:

MsExcel.Range("B2").Value = List5.List(0)

MsExcel.Range("c2").Value = List5.List(1)

my list box name is listbox5. Thank you for any help you can provide

Edit by belisarius

Just adding text from the author's comment

here is the code I am trying to use it with:

Private Sub mdofficecommandbutton_Click() 
   Workbooks.Open FileName:="C:\Documents and Settings\o075535\Desktop\Workstation- printer setup\Workstation blank template.xls" 
   Sheets("LWS NEW BUILD").Cells(3, 6) = txtdepartment.Text 
   Sheets("LWS NEW BUILD").Cells(3, 7) = 17012 
   Sheets("LWS NEW BUILD").Cells(3, 8) = txtprinter.Text 
   Sheets("LWS NEW BUILD").Cells(3, 7) = 17004 
   Sheets("LWS NEW BUILD").Cells(3, 8) = txtprinter.Text 
   MsExcel.Range("B2").Value = List5.List(0) 
   MsExcel.Range("c2").Value = List5.List(1) 
End Sub
1
here is the code I am trying to use it with:Slinkey
Private Sub mdofficecommandbutton_Click() Workbooks.Open FileName:="C:\Documents and Settings\o075535\Desktop\Workstation- printer setup\Workstation blank template.xls" Sheets("LWS NEW BUILD").Cells(3, 6) = txtdepartment.Text Sheets("LWS NEW BUILD").Cells(3, 7) = 17012 Sheets("LWS NEW BUILD").Cells(3, 8) = txtprinter.Text Sheets("LWS NEW BUILD").Cells(3, 7) = 17004 Sheets("LWS NEW BUILD").Cells(3, 8) = txtprinter.Text MsExcel.Range("B2").Value = List5.List(0) MsExcel.Range("c2").Value = List5.List(1) End SubSlinkey
Shouldn't "List5" be "listbox5"?Marc Thibault

1 Answers

0
votes

Here is an example

Sheet3.Range("E4").Value = Sheet3.ListObjects(1).ListRows(3).Range(1, 2).Value

It takes the 1st list, 3rd row, 2nd column value and places it into "E4". You reference the list with the ListObjects member.

Here is how to copy many values from a list into the worksheet

Dim n As Integer
n = Sheet3.ListObjects(1).ListRows.Count

Sheet3.Range("E5").Resize(n, 1).Value = _
  Sheet3.ListObjects(1).ListRows(1).Range(1, 2).Resize(n, 1).Value

the variable n holds the number to copy (here n=#rows) and then use the 2nd column (with Range(1,2)) with n-th rows.