PC Review


Reply
Thread Tools Rate Thread

Application_defined or object-defined error - Run 1004 error

 
 
Varun
Guest
Posts: n/a
 
      25th Mar 2009
Folks,

I am running into application_defined or object-defined error at the PROBLEM
LINE in following code below.

I am assuming that there are more same type error in the code. Please let
me know how to get around this.

Thanks,
Varun


Private Sub CommandButton1_Click()

Dim ddifn As String
Dim ddifnWkBk As Workbook

Dim Di As Variant
Dim Si As Variant
Dim fsl As Integer
Dim fdl As Integer
Dim sth As Integer
Dim dth As Integer
Dim x As Integer
Dim y As Integer


ddifn = Application.GetOpenFilename(FileFilter:="Excel Files, *.xls", _
Title:="Please select layer stackup file received from fab shop")

Set ddifnWkBk = Workbooks.Open(ddifn, , ReadOnly)

'create Temp worksheet

Call CreateTempSheet(ddifnWkBk)
ddifnWkBk.Close

endrows = Worksheets("Temp").UsedRange.Rows.Count

'Find Copper row and column

For copperRows = 1 To endrows
If Worksheets("Temp").Cells(a, b) = "Copper" Then <------PROBLEM LINE
cRow = a
cCol = b
Exit For
End If
Next copperRows

'Find laminate row and column

For laminateRows = 1 To endrows
If Worksheets("Temp").Cells(c, d) = "Laminate / PrePreg:" Then
lRow = c
lCol = d
Exit For
End If
Next laminateRows

'Find Impedance Requirements row and column

For impedance_rows = 1 To endrows
If Worksheets("Temp").Cells(m, n) = "Impedance Requirements:" Then
iRow = m
iCol = n
Exit For
End If
Next impedance_rows

'Find signal/copper layer thicknesses
'cRow is where copper starts and iRow is end (Impedance Requirements)

For i = cRow To iRow

If Worksheets("Temp").Cells(i, cCol) <> "" Then
If fdl <> 0 Then
Di(x) = dth
fdl = 0
x = x + 1
End If
sth = sth + Worksheets("Temp").Cells(i, cCol).Value
fsl = 1
dth = 0
End If

If Worksheets("Temp").Cells(i, lCol) <> "" Then
If fsl <> 0 Then
Si(y) = sth
fsl = 0
y = y + 1
End If
dth = dth + Worksheets("Temp").Cells(i, lCol)
fdl = 1
sth = 0
End If

Next i

Si(y) = sth

End Sub
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      25th Mar 2009
You have not declared what "a" and "b" are equal to, nor their data types.

Dim a As Long, b As Long

a = #?
b = #?


"Varun" <(E-Mail Removed)> wrote in message
news:A52C86AF-9843-4C7D-986C-(E-Mail Removed)...
> Folks,
>
> I am running into application_defined or object-defined error at the
> PROBLEM
> LINE in following code below.
>
> I am assuming that there are more same type error in the code. Please let
> me know how to get around this.
>
> Thanks,
> Varun
>
>
> Private Sub CommandButton1_Click()
>
> Dim ddifn As String
> Dim ddifnWkBk As Workbook
>
> Dim Di As Variant
> Dim Si As Variant
> Dim fsl As Integer
> Dim fdl As Integer
> Dim sth As Integer
> Dim dth As Integer
> Dim x As Integer
> Dim y As Integer
>
>
> ddifn = Application.GetOpenFilename(FileFilter:="Excel Files, *.xls", _
> Title:="Please select layer stackup file received from fab shop")
>
> Set ddifnWkBk = Workbooks.Open(ddifn, , ReadOnly)
>
> 'create Temp worksheet
>
> Call CreateTempSheet(ddifnWkBk)
> ddifnWkBk.Close
>
> endrows = Worksheets("Temp").UsedRange.Rows.Count
>
> 'Find Copper row and column
>
> For copperRows = 1 To endrows
> If Worksheets("Temp").Cells(a, b) = "Copper" Then <------PROBLEM LINE
> cRow = a
> cCol = b
> Exit For
> End If
> Next copperRows
>
> 'Find laminate row and column
>
> For laminateRows = 1 To endrows
> If Worksheets("Temp").Cells(c, d) = "Laminate / PrePreg:" Then
> lRow = c
> lCol = d
> Exit For
> End If
> Next laminateRows
>
> 'Find Impedance Requirements row and column
>
> For impedance_rows = 1 To endrows
> If Worksheets("Temp").Cells(m, n) = "Impedance Requirements:" Then
> iRow = m
> iCol = n
> Exit For
> End If
> Next impedance_rows
>
> 'Find signal/copper layer thicknesses
> 'cRow is where copper starts and iRow is end (Impedance Requirements)
>
> For i = cRow To iRow
>
> If Worksheets("Temp").Cells(i, cCol) <> "" Then
> If fdl <> 0 Then
> Di(x) = dth
> fdl = 0
> x = x + 1
> End If
> sth = sth + Worksheets("Temp").Cells(i, cCol).Value
> fsl = 1
> dth = 0
> End If
>
> If Worksheets("Temp").Cells(i, lCol) <> "" Then
> If fsl <> 0 Then
> Si(y) = sth
> fsl = 0
> y = y + 1
> End If
> dth = dth + Worksheets("Temp").Cells(i, lCol)
> fdl = 1
> sth = 0
> End If
>
> Next i
>
> Si(y) = sth
>
> End Sub



 
Reply With Quote
 
joel
Guest
Posts: n/a
 
      25th Mar 2009
a and b are not defined. Set a and b to some value before the FOR loop.

"Varun" wrote:

> Folks,
>
> I am running into application_defined or object-defined error at the PROBLEM
> LINE in following code below.
>
> I am assuming that there are more same type error in the code. Please let
> me know how to get around this.
>
> Thanks,
> Varun
>
>
> Private Sub CommandButton1_Click()
>
> Dim ddifn As String
> Dim ddifnWkBk As Workbook
>
> Dim Di As Variant
> Dim Si As Variant
> Dim fsl As Integer
> Dim fdl As Integer
> Dim sth As Integer
> Dim dth As Integer
> Dim x As Integer
> Dim y As Integer
>
>
> ddifn = Application.GetOpenFilename(FileFilter:="Excel Files, *.xls", _
> Title:="Please select layer stackup file received from fab shop")
>
> Set ddifnWkBk = Workbooks.Open(ddifn, , ReadOnly)
>
> 'create Temp worksheet
>
> Call CreateTempSheet(ddifnWkBk)
> ddifnWkBk.Close
>
> endrows = Worksheets("Temp").UsedRange.Rows.Count
>
> 'Find Copper row and column
>
> For copperRows = 1 To endrows
> If Worksheets("Temp").Cells(a, b) = "Copper" Then <------PROBLEM LINE
> cRow = a
> cCol = b
> Exit For
> End If
> Next copperRows
>
> 'Find laminate row and column
>
> For laminateRows = 1 To endrows
> If Worksheets("Temp").Cells(c, d) = "Laminate / PrePreg:" Then
> lRow = c
> lCol = d
> Exit For
> End If
> Next laminateRows
>
> 'Find Impedance Requirements row and column
>
> For impedance_rows = 1 To endrows
> If Worksheets("Temp").Cells(m, n) = "Impedance Requirements:" Then
> iRow = m
> iCol = n
> Exit For
> End If
> Next impedance_rows
>
> 'Find signal/copper layer thicknesses
> 'cRow is where copper starts and iRow is end (Impedance Requirements)
>
> For i = cRow To iRow
>
> If Worksheets("Temp").Cells(i, cCol) <> "" Then
> If fdl <> 0 Then
> Di(x) = dth
> fdl = 0
> x = x + 1
> End If
> sth = sth + Worksheets("Temp").Cells(i, cCol).Value
> fsl = 1
> dth = 0
> End If
>
> If Worksheets("Temp").Cells(i, lCol) <> "" Then
> If fsl <> 0 Then
> Si(y) = sth
> fsl = 0
> y = y + 1
> End If
> dth = dth + Worksheets("Temp").Cells(i, lCol)
> fdl = 1
> sth = 0
> End If
>
> Next i
>
> Si(y) = sth
>
> End Sub

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Mar 2009
In this code:

For copperRows = 1 To endrows
If Worksheets("Temp").Cells(a, b) = "Copper" Then <------PROBLEM LINE
cRow = a
cCol = b
Exit For
End If
Next copperRows

a and b have never been defined. So excel will treat them as 0's.

Maybe...

What column are you looking through to find "Copper"?

If it were column A, I would expect the code would look more like:
For copperRows = 1 To endrows
If Worksheets("Temp").Cells(CopperRows, "A") = "Copper" Then
cRow = copperrows
cCol = "A"
Exit For
End If
Next copperRows

Varun wrote:
>
> Folks,
>
> I am running into application_defined or object-defined error at the PROBLEM
> LINE in following code below.
>
> I am assuming that there are more same type error in the code. Please let
> me know how to get around this.
>
> Thanks,
> Varun
>
> Private Sub CommandButton1_Click()
>
> Dim ddifn As String
> Dim ddifnWkBk As Workbook
>
> Dim Di As Variant
> Dim Si As Variant
> Dim fsl As Integer
> Dim fdl As Integer
> Dim sth As Integer
> Dim dth As Integer
> Dim x As Integer
> Dim y As Integer
>
> ddifn = Application.GetOpenFilename(FileFilter:="Excel Files, *.xls", _
> Title:="Please select layer stackup file received from fab shop")
>
> Set ddifnWkBk = Workbooks.Open(ddifn, , ReadOnly)
>
> 'create Temp worksheet
>
> Call CreateTempSheet(ddifnWkBk)
> ddifnWkBk.Close
>
> endrows = Worksheets("Temp").UsedRange.Rows.Count
>
> 'Find Copper row and column
>
> For copperRows = 1 To endrows
> If Worksheets("Temp").Cells(a, b) = "Copper" Then <------PROBLEM LINE
> cRow = a
> cCol = b
> Exit For
> End If
> Next copperRows
>
> 'Find laminate row and column
>
> For laminateRows = 1 To endrows
> If Worksheets("Temp").Cells(c, d) = "Laminate / PrePreg:" Then
> lRow = c
> lCol = d
> Exit For
> End If
> Next laminateRows
>
> 'Find Impedance Requirements row and column
>
> For impedance_rows = 1 To endrows
> If Worksheets("Temp").Cells(m, n) = "Impedance Requirements:" Then
> iRow = m
> iCol = n
> Exit For
> End If
> Next impedance_rows
>
> 'Find signal/copper layer thicknesses
> 'cRow is where copper starts and iRow is end (Impedance Requirements)
>
> For i = cRow To iRow
>
> If Worksheets("Temp").Cells(i, cCol) <> "" Then
> If fdl <> 0 Then
> Di(x) = dth
> fdl = 0
> x = x + 1
> End If
> sth = sth + Worksheets("Temp").Cells(i, cCol).Value
> fsl = 1
> dth = 0
> End If
>
> If Worksheets("Temp").Cells(i, lCol) <> "" Then
> If fsl <> 0 Then
> Si(y) = sth
> fsl = 0
> y = y + 1
> End If
> dth = dth + Worksheets("Temp").Cells(i, lCol)
> fdl = 1
> sth = 0
> End If
>
> Next i
>
> Si(y) = sth
>
> End Sub


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find: runtime error 1004 Application-defined or object-defined error inspired Microsoft Excel Discussion 3 30th Nov 2010 12:34 PM
Run Time Error 1004 Application-defined or object-defined error forsimple loop? Need help with what's wrong? Naji Microsoft Excel Programming 2 16th Oct 2009 05:45 PM
Export a chart in a GIF file. Run-time error '1004': Application-defined or object-defined error; cschiffers@gmail.com Microsoft Excel Programming 5 17th Sep 2007 12:48 PM
Runtime Error 1004: Application defined or object defined error =?Utf-8?B?QWNjZXNzIG4wMGI=?= Microsoft Excel Programming 2 5th Apr 2006 02:58 AM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Microsoft Excel Programming 6 9th Jun 2004 03:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:16 PM.