[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
Re: Run time error 1004, can't figure it out
Quote:
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
Re: Run time error 1004, can't figure it out
Quote:
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.
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