|
-
Jun 2nd, 2011, 05:41 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Run time error 1004, can't figure it out
So I'm nowhere near a professional VBA developer here, but I've done this before for working with huge spreadsheets at a previous job and didn't feel this dumb.
I keep getting the run time error 1004: Application-defined or object-defined error
and this is all I have:
Code:
Sub dosomething()
Sheet1.Activate
Sheet1.Visible = True
Sheet1.Select
Dim i As Integer
For i = 0 To 10 'Sheet1.Rows.Count
If Sheet1.Cells(i, 6) <> "" Then
Sheet1.Cells(1, 12) = Sheet1.Cells(1, 12) + Chr(13) + "duh = ListView1.ListItems.Add(,," + Sheet1.Cells(i, 1) + ")"
End If
Next i
End Sub
I've tried searching, but to no avail thus far. The only thing I came up with from searching was the first part, using activate visible and select, but that didn't fix it.
In case anyone is wondering, I have an excel sheet and I want to import all of the values into a multi-column listview in VB, which I have working but it is slow because it's opening the workbook to pull the values. I want to produce code to load the information in directly from my project so I don't have to have the additional excel workbook. I was testing my first few lines of code to make sure I remembered what I was doing, and have spent the last 30 minutes frustratingly searching for why this won't work. Please help
Thank you in advance,
Eric
Government is another way to say better…than…you.
It’s like ice but no pick, a murder charge that won’t stick,
it’s like a whole other world where you can smell the food,
but you can’t touch the silverware.
Huh, what luck. Fascism you can vote for.
Humph, isn’t that sweet?
And we’re all gonna die some day, because that’s the American way
-Stone Sour
-
Jun 3rd, 2011, 03:18 AM
#2
Re: Run time error 1004, can't figure it out
Sheet1.Cells(1, 12) = Sheet1.Cells(1, 12) + Chr(13) + "duh = ListView1.ListItems.Add(,," + Sheet1.Cells(i, 1) + ")"
what is this line actually supposed to do?, looks really odd, but does not produce error
unless i = 0
sheet1.cells(i ,1), no row 0
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 3rd, 2011, 07:55 AM
#3
Lively Member
Re: Run time error 1004, can't figure it out
 Originally Posted by Skitchen8
Code:
For i = 0 To 10 'Sheet1.Rows.Count
If Sheet1.Cells(i, 6) <> "" Then
That "for" loop starts at zero, effectively making your first pass through that if statement asking if Sheet1.Cells(0,6) is blank.
The .Cells function is not zero-based. You need to start at 1.
Making a reference to .Cells(0,0) will give you a undefined object error because no such cell will ever exist.
-
Jun 3rd, 2011, 02:39 PM
#4
Thread Starter
Frenzied Member
Re: Run time error 1004, can't figure it out
*smashes face on keyboard*
I don't know how this never occurred to me... thank you
Government is another way to say better…than…you.
It’s like ice but no pick, a murder charge that won’t stick,
it’s like a whole other world where you can smell the food,
but you can’t touch the silverware.
Huh, what luck. Fascism you can vote for.
Humph, isn’t that sweet?
And we’re all gonna die some day, because that’s the American way
-Stone Sour
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|