#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
xpath error? Runtime Error 13 type mismatch Steve M[_2_] Excel Discussion (Misc queries) 0 January 17th 08 01:16 AM
Conditional Formatting - Run Time Error '13' Type Mismatch Error ksp Excel Programming 0 July 11th 06 07:06 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"