![]() |
type error
Here's my code:
Private Sub cbAddContents_Click() Dim ind As Integer Dim tot_items As Integer tot_items = ListBox1.ListCount For ind = 1 To tot_items If ListBox1(ind).Checked = True Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1(ind).Value End If Next ind When I get to the if statement, I get a Type Mismatch error. What am I doing wrong? David |
type error
David, I'm assuming you've allowed multiple select in your listbox and are
trying to move those selections into the spreadsheet. Is that correct? I think you need to reference the list item of the listbox: If ListBox1.Selected(ind) Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1.List(ind) End If Let me know if this is not what you are trying to do. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Here's my code: Private Sub cbAddContents_Click() Dim ind As Integer Dim tot_items As Integer tot_items = ListBox1.ListCount For ind = 1 To tot_items If ListBox1(ind).Checked = True Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1(ind).Value End If Next ind When I get to the if statement, I get a Type Mismatch error. What am I doing wrong? David |
type error
Charles,
Thanks a lot, that is the situation and that's what I'm trying to do. However the if statement is now getting an error: Run time error -2147024809 (80070057) Could not get the Selected property. Invalid argument. David "Charles Chickering" wrote: David, I'm assuming you've allowed multiple select in your listbox and are trying to move those selections into the spreadsheet. Is that correct? I think you need to reference the list item of the listbox: If ListBox1.Selected(ind) Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1.List(ind) End If Let me know if this is not what you are trying to do. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Here's my code: Private Sub cbAddContents_Click() Dim ind As Integer Dim tot_items As Integer tot_items = ListBox1.ListCount For ind = 1 To tot_items If ListBox1(ind).Checked = True Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1(ind).Value End If Next ind When I get to the if statement, I get a Type Mismatch error. What am I doing wrong? David |
type error
Try dexrementing your index, the list is 0 based
For ind = 0 to tot_items - 1 Let me know how that goes. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Charles, Thanks a lot, that is the situation and that's what I'm trying to do. However the if statement is now getting an error: Run time error -2147024809 (80070057) Could not get the Selected property. Invalid argument. David "Charles Chickering" wrote: David, I'm assuming you've allowed multiple select in your listbox and are trying to move those selections into the spreadsheet. Is that correct? I think you need to reference the list item of the listbox: If ListBox1.Selected(ind) Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1.List(ind) End If Let me know if this is not what you are trying to do. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Here's my code: Private Sub cbAddContents_Click() Dim ind As Integer Dim tot_items As Integer tot_items = ListBox1.ListCount For ind = 1 To tot_items If ListBox1(ind).Checked = True Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1(ind).Value End If Next ind When I get to the if statement, I get a Type Mismatch error. What am I doing wrong? David |
type error
Thanks, but it'll have to wait until Friday.
Have a happy thanksgiving! David "Charles Chickering" wrote: Try dexrementing your index, the list is 0 based For ind = 0 to tot_items - 1 Let me know how that goes. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Charles, Thanks a lot, that is the situation and that's what I'm trying to do. However the if statement is now getting an error: Run time error -2147024809 (80070057) Could not get the Selected property. Invalid argument. David "Charles Chickering" wrote: David, I'm assuming you've allowed multiple select in your listbox and are trying to move those selections into the spreadsheet. Is that correct? I think you need to reference the list item of the listbox: If ListBox1.Selected(ind) Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1.List(ind) End If Let me know if this is not what you are trying to do. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Here's my code: Private Sub cbAddContents_Click() Dim ind As Integer Dim tot_items As Integer tot_items = ListBox1.ListCount For ind = 1 To tot_items If ListBox1(ind).Checked = True Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1(ind).Value End If Next ind When I get to the if statement, I get a Type Mismatch error. What am I doing wrong? David |
type error
Charles,
Right before I left on Wednesday, I checked and you were right. (I didn't need to decrement though.) The problem was that the index was out of range, I changed it to 0 to tot_items - 1 and it worked fine. If the error message had been: "Out of range" I would have realized that on my own. Thanks a lot for your help! David "Charles Chickering" wrote: Try dexrementing your index, the list is 0 based For ind = 0 to tot_items - 1 Let me know how that goes. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Charles, Thanks a lot, that is the situation and that's what I'm trying to do. However the if statement is now getting an error: Run time error -2147024809 (80070057) Could not get the Selected property. Invalid argument. David "Charles Chickering" wrote: David, I'm assuming you've allowed multiple select in your listbox and are trying to move those selections into the spreadsheet. Is that correct? I think you need to reference the list item of the listbox: If ListBox1.Selected(ind) Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1.List(ind) End If Let me know if this is not what you are trying to do. -- Charles Chickering "A good example is twice the value of good advice." "David Gerstman" wrote: Here's my code: Private Sub cbAddContents_Click() Dim ind As Integer Dim tot_items As Integer tot_items = ListBox1.ListCount For ind = 1 To tot_items If ListBox1(ind).Checked = True Then Worksheets("SF 701").Cells(8, 1).Offset(0, ind).Value = ListBox1(ind).Value End If Next ind When I get to the if statement, I get a Type Mismatch error. What am I doing wrong? David |
All times are GMT +1. The time now is 02:40 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com