Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default An error in some code I did not write

I looked through the whole function. Letter 'o' isn't defined as a variable,
it is not assigned a value.

What value does o have in it?

"Aaron" wrote:

Sorry, I figured someone would have seen a letter used in an offset like that
and be able to point me in the right direction. Here is the whole sub, does
this help?

Sub rptOOH()
Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

Sheets("ORDERHEAD").Activate
Range("A1").Select
Sheets("ECLLINE").Activate
Cells.Select
Selection.Copy
Sheets("OOH Details").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("ECSLINESP").Activate
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("OOH Details").Select
x = Cells.Find(What:="*", SearchOrder:=xlByRows,
SearchDirection:=xlPrevious).Row + 1
Cells(x, 1).Select
ActiveSheet.Paste
x = Cells.Find(What:="*", SearchOrder:=xlByRows,
SearchDirection:=xlPrevious).Row

While x 1
ord = Cells(x, 1)
Set FORD = Sheets("ORDERHEAD").Columns("A:A").Find(What:=ord,
LookIn:=xlValues, lookat:=xlWhole)
If FORD Is Nothing Then
Cells(x, 1).EntireRow.Delete
Else
Cells(x, 9) = FORD.Offset(0, 1) 'date
Cells(x, 10) = FORD.Offset(0, 2) 'Cust Code
Cells(x, 11) = FORD.Offset(0, 11) 'cust name
Cells(x, 12) = FORD.Offset(0, 10) 'incom code correct
If Cells(x, 12) = "" Or (Cells(x, 12) < 1 And Cells(x, 12) < 2 And
Cells(x, 12) < 4) Then
Cells(x, 12) = 1
End If

Cells(x, 13) = FORD.Offset(0, 8) 'incom code EHIC
On Error Resume Next
Cells(x, 14) = Cells(x, 13) - Cells(x, 12)
On Error GoTo 0
Cells(x, 15) = Format("'" & Cells(x, 5), "") & Format(Cells(x, 12), "")
Cells(x, 16) = FORD.Offset(o, 13)
End If
x = x - 1
Wend
Cells(1, 9) = "Date"
Cells(1, 10) = "Cust Code"
Cells(1, 11) = "Cust Name"
Cells(1, 12) = "IntCom Code"
Cells(1, 13) = "EHIC"
Cells(1, 8).FormulaR1C1 = "=SUM(R[1]C:R[65535]C)"
Range("A1:M1").Select
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
Sheets("ORDERHEAD").Cells.ClearContents
Sheets("ECLLINE").Cells.ClearContents
Sheets("ECSLINESP").Cells.ClearContents
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Sheets("OOH Details").Select
End Sub



"George Nicholson" wrote:

so I'm not sure what it means, column o maybe?


Well, that's sort of a key point, don't u think? What is the value of o when
the line fails (it should be a number)? What is the address of FORD at that
point?

The line in question assigns Cell(x,16) the value of the cell at
FORD.Offset(+/- Num of rows,+/-Num of Cols).

We know FORD is in column A. If FORD's row number + o results in a value
less than zero, you will get an error..

'**************
Frankly, given the snippet provided, I have a hard time this code will even
run as far as you say it does. I don't think the compiler would let it. The
following generates a "End If without block If" error:

While x 1
' NO If...Then
' NO Wend
End If

but it hangs up on the second to last line

....it hangs with what error message?? Being more specific might make it
easier to help you.

*If* you get the same error message I do, then I'd suspect that the code
(not worksheet) has changed since last month and i would consider opening a
backup copy of the file (from when you 'know" it worked) and look at the
same section of code and see what it USED to be when it was working. My
guess is that the While... should be "If x1 Then". (Changing the End If to
Wend is a bad idea because it would create an endless loop since x isn't
being changed).

(All this assumes that we're looking at a complete code snippet).

HTH,



"Aaron" wrote in message
...
I'm afriad not. "o" is used a number of times in the code with no
problem,
however "o" is not defined anywhere in the code, so I'm not sure what it
means, column o maybe?

"barnabel" wrote:



"Aaron" wrote:

Amoung other things the code say what you see below, but it hangs up on
the
second to last line, "Cells(x, 16) = FORD.Offset(o, 13)" the code
worked
last month when we used it. What might have changed in the spreadsheet
to
make it hang up here?


x = Cells.Find(What:="*", SearchOrder:=xlByRows,
SearchDirection:=xlPrevious).Row + 1
Cells(x, 1).Select
ActiveSheet.Paste
x = Cells.Find(What:="*", SearchOrder:=xlByRows,
SearchDirection:=xlPrevious).Row

While x 1
ord = Cells(x, 1)
Set FORD = Sheets("ORDERHEAD").Columns("A:A").Find(What:=ord,
LookIn:=xlValues, lookat:=xlWhole)

Cells(x, 13) = FORD.Offset(0, 8) 'incom code EHIC
On Error Resume Next
Cells(x, 14) = Cells(x, 13) - Cells(x, 12)
On Error GoTo 0
Cells(x, 15) = Format("'" & Cells(x, 5), "") & Format(Cells(x, 12),
"")
Cells(x, 16) = FORD.Offset(o, 13)
End If
Is that supposed to be a zero not the letter O?




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
could someone write me a VB code? thanks Morgan New Users to Excel 6 March 10th 10 01:20 PM
Write VB6 code to be used with VBA avi Excel Programming 1 April 8th 07 02:32 PM
Write code to Write Code Kstalker[_43_] Excel Programming 6 November 25th 05 12:30 AM
Code to write out all lines of code davidm Excel Programming 3 August 5th 05 04:26 AM
Application error when attempting to write code to a workbook Jared Excel Programming 1 November 17th 04 08:17 PM


All times are GMT +1. The time now is 08:47 PM.

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"