Hello everyone this is my first and hopefully last question I will ask on here. I am having trouble with vba in excel and I was hoping that someone could answer it
Hints for the Copy command button code: Use a For -Next loop to go through each item of the list box to see if it were selected. Remember a list box is zero-based. Use the lstListBox.ListCount property of the list to end the For-Next loop. (lstListBox.ListCount - 1) Within the For-Next loop use an If statement to see whether an item in the list is selected using the lstListBox.Selected(intIndex) property which is of Boolean data type. If a list value is selected increment a counter (intCounter) to keep track of how many items were selected and put in a statement to display the selected list value to a row in column B of the spreadsheet. Use this counter in the cells object row number to display the selected item in the list to column B of the spreadsheet. example: Cells(intCounter,"B").Value = lstListBox.List(intIndex) See the pseudocode listed below: (These statements can be used as comments in your code) Loop thru the ten items in the list Check if an item in the list is selected If Yes then increment a counter display the selected item from the list in the counter number row of column B of the spreadsheet End the Check or Select structure End the Loop structure P.S. Convert the pseudocode listed above to For-Next and If-End If looping and select coding structures.
So what I am really trying to do is copy some information from a listbox into a different column. If anyone could help that would be great. Can't go home until I have this resolved. This is what I have so far it could all be garbage I really don't know
Private Sub CommandButton1_Click() Dim intNumberOfItemsInList As Integer Dim lstListBoxListCount As Integer Dim ItemsCount As Integer Dim strInput As String Dim intIndex As Integer Dim lstlistbox As ListBox Dim intcounter As Integer
'Loop thru the ten items in the list For intNumberOfItemsInList = 0 To 9 'Check if an item in the list is selected If Yes then
Next lstlistbox.ListCount - 1
'increment a counter
Cells(intcounter, "B").Value = lstlistbox.List(intIndex)
' display the selected item from the list in the counter number row of column B of the spreadsheet
Range("B1:B10").Select
ActiveSheet.Paste
'End the Check or Select structure
End Select
'End the Loop structure
End Sub
The comments are supposed to help "guide us" through the program, but it has not helped me. Thanks again. If you have any questions about the question please let me know. I will try to answer them to the best of my ability.