PDA

View Full Version : How can I grab the data from a LISTBOX and insert it on COLUMN "G1"



dkipnai
05-12-2010, 09:18 AM
Hi Friends:
My name is Kipnai.

Background:
I am a newbie. I have already developed a portion of CODE within a form and several control buttons. I have a data sorter which from LISTBOX-A and popupates LISTBOX-B.

QUESTION:
Please help me with a CODE thread which can Grab the data from a LISTBOX-B and insert it on COLUMN "G1" on a spreadsheet.

The following code by Simon works only for one line (sentence)


Private Sub CommandButton10_Click()
Range("G1") = UserForm2.ListBox2.Value
End Sub

Thank you Simon for such a quick response. I can see some light at the end of the tunnel. But I thick now I need a CODE TO LOOP through the LISTBOX-B BUT HOW do I go about it? Please could you add more light?

Please help.

Kipnai

mbarron
05-12-2010, 09:36 AM
Try this:


Sub CommandButton10_Click()
Dim i As Integer
For i = 0 To UBound(UserForm2.ListBox2.List)
Range("G" & i + 1) =UserForm2.ListBox2.List(i)
Next
End Sub

GTO
05-12-2010, 09:37 AM
Maybe:

Private Sub CommandButton1_Click()
Dim i As Long

For i = 0 To Me.ListBox1.ListCount - 1
Range("G1").Offset(i).Value = Me.ListBox1.list(i)
Next

End Sub


Hope that helps,

Mark

Shiraj_Hoque
12-01-2010, 12:33 PM
Hi Newbie here,
I have a code that takes information from one ListBox to another. Now I need the selected information to go from the second listbox to a spreadsheet.
I can get the information on the spreadsheet but its not dynamic enough. I think I need to incorporate a COUNTA with the Offset but dont know how to in VBA.

can someone guide me in the right direction and offer notes to explain. I'm keen to learn so would be great.

Private Sub CommandButton3_Save_to_Site_Specific_Lookups_Click()
Dim C As Integer, R As Integer
Dim RefCell As Range
Set RefCell = Worksheets("KB Wide Lookup").Range("D2")

With UserForms(0)
For R = 0 To ListBox4_Site_Specific.ListCount - 1
For C = 0 To ListBox4_Site_Specific.ColumnCount - 1
RefCell.Offset(R, C).Value = ListBox4_Site_Specific.List(R, C)
Next C
Next R
End With

End Sub