Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Application-defined or object-defined error' 1

Status
Not open for further replies.

sarmizzle

Programmer
Oct 15, 2007
2
US
Hey
I've written a simple VBA code that references several Excel worksheets, but every time I compile it, I get 'Application-defined or object-defined error.' What am I doing wrong?

Here's my code:



Sub errorpropagationforQ()
For w = 2 To 134
For a = 1 To 12
If a = 2 Then p = 4 And o = 9
If a = 3 Then p = 5 And o = 11
If a = 4 Then p = 6 And o = 12
If a = 5 Then p = 7 And o = 13
If a = 6 Then p = 10 And o = 16
If a = 7 Then p = 11 And o = 17
If a = 8 Then p = 13 And o = 20
If a = 9 Then p = 14 And o = 21
If a = 10 Then p = 15 And o = 22
If a = 11 Then p = 17 And o = 24

If a = 1 Then y = y + (1 / Worksheets("Coefficients").Cells(3, 3)) ^ 2 * (Worksheets("Coefficients").Cells(3, 4)) ^ 2

If a = 12 Then y = y + (Worksheets("Normalized Expanded").Cells(w + 1, 25)) ^ 2 * (Worksheets("Coefficients").Cells(3, 4)) ^ 2

If a > 2 And a < 12 Then y = y + (Log(Worksheets("Normalized Expanded").Cells(w, o))) ^ 2 * Worksheets("Coefficients").Cells(p, 4) ^ 2 (THIS IS WHERE IT IS HILITED)

.
.
.
.
.
.
Thanks,
Miz
 



What is the value of ...

o

???

o NEVER gets a value!!!!!!

You can't do this...
Code:
        If a = 2 Then p = 4 [b]And o = 9[/b]
you can do this...
Code:
[code]
        If a = 2 Then 
           p = 4
           o = 9
        End if
[/b]


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 




or...
Code:
        If a = 2 Then p = 4: o = 9

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
2 FOR statements with no NEXT statements?

The early bird may get the worm, but the second mouse gets the cheese in the trap.
 
That would be a kicker, but I suspect they are just not included. sarmizzle, please use the TGML code tags when posting code.

BTW: are you using Option Explicit?

In any case, as Skip points out (but does not actually say so....), AND is a LOGIC operator, not an instruction. You are trying to use it as an instruction.

AND does not action (do) anything, it tests the logical conjunction between two expressions. It is Boolean and returns True, False....or Null. Nothing more. That's all she wrote.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top