View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Joseph Atie Joseph Atie is offline
external usenet poster
 
Posts: 19
Default help with a piece of code

Im getting the error Method 'Cells' of object '_Global' failed on the
following function

My understanding is this is because im havent explicitly defined the sheet
im working in.

I have placed **ERROR ON THE LINE BELOW*** to indicate where the error is

little help please.

If i add another call to the sheet calc inside the loop then i get overflow
errors.

The weird thing is the code still runs and still produces the correct output.

If you need to see the other functions this function calls just ask and ill
post them as well.

Sub Build_Calc()

Call Filter

Dim diff As Integer
Dim cell As Object
Dim counter As Integer
Dim counter1 As Integer
Dim no_task As Integer
Dim start_date
Dim end_date
Dim start_time
Dim end_time
Dim shift
Dim day_shift
Dim night_shift
Dim labour As Integer


Sheets("junk").Select
Range("L7").Select
diff = Selection.Value
diff = diff + 1
Range("L3").Select
start_date = Selection.Value

Sheets("Calc").Select
Cells.Select
Selection.ClearContents

For counter = 1 To (diff * 2)
Cells(1, counter).Select
ActiveCell.Value = start_date
Cells(2, counter).Select
ActiveCell.Value = "Day"
counter = counter + 1
Cells(1, counter).Select
ActiveCell.Value = start_date
Cells(2, counter).Select
ActiveCell.Value = "Night"
start_date = start_date + 1
If counter = (diff * 2) Then
Cells(2, counter + 1).Select
ActiveCell.Value = "Hours"
End If
Next counter


Columns("A:A").Select
Selection.Insert shift:=xlToRight

Sheets("junk").Select
Columns("C:C").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Copy
Sheets("Calc").Select
Range("A2").Select
ActiveSheet.Paste


Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Rows("1:1").EntireRow.AutoFit
Sheets("junk").Select
Range("l9").Select
no_task = Selection.Value
Range("l11").Select
day_shift = Selection.Value
Range("l13").Select
night_shift = Selection.Value

For counter1 = 1 To no_task
Sheets("junk").Select
Cells(counter1 + 1, 5).Select
labour = ActiveCell.Value
Cells(counter1 + 1, 11).Select
shift = ActiveCell.Value
Cells(counter1 + 1, 6).Select
start_date = ActiveCell.Value
Cells(counter1 + 1, 8).Select
end_date = ActiveCell.Value

Sheets("calc").Select

For counter = 1 To (diff * 2)
If shift = "24" Then
' 24 hour calendar
' day shift
*** ERROR ON THE LINE BELOW***
If Cells(1, counter).Value start_date And Cells(1,
counter).Value < end_date Then
Cells(counter1 + 2, counter).Value = labour
counter = counter + 1
ElseIf (Cells(1, counter).Value = start_date And
Cells(1, counter).Value < end_date) And start_time < night_shift Then
Cells(counter1 + 2, counter).Value = labour
counter = counter + 1
ElseIf (Cells(1, counter).Value start_date And
Cells(1, counter).Value = end_date) And end_time = day_shift Then
Cells(counter1 + 2, counter).Value = labour
counter = counter + 1
ElseIf (Cells(1, counter).Value = start_date And
Cells(1, counter).Value = end_date) And end_time = day_shift And start_time
< night_shift Then
Cells(counter1 + 2, counter).Value = labour
counter = counter + 1
Else
counter = counter + 1

End If
' night shift

If Cells(1, counter).Value start_date And Cells(1,
counter).Value < end_date Then
Cells(counter1 + 2, counter).Value = labour
ElseIf (Cells(1, counter).Value = start_date And
Cells(1, counter).Value < end_date) And start_time day_shift Then
Cells(counter1 + 2, counter).Value = labour
ElseIf (Cells(1, counter).Value start_date And
Cells(1, counter).Value = end_date) And end_time night_shift Then
Cells(counter1 + 2, counter).Value = labour
ElseIf (Cells(1, counter).Value = start_date And
Cells(1, counter).Value = end_date) And end_time night_shift Then
Cells(counter1 + 2, counter).Value = labour
ElseIf (Cells(1, counter).Value =
start_date And Cells(1, counter + 1).Value = end_date) And end_time <
day_shift Then
Cells(counter1 + 2, counter).Value =
labour


End If
' 12 hour calendar
ElseIf Cells(1, counter).Value = start_date And Cells(1,
counter).Value <= end_date Then
Cells(counter1 + 2, counter).Value = labour
counter = counter + 1
End If
'add no of hours per shift
Cells(counter1 + 2, (diff * 2) + 2).Select
ActiveCell.Value = shift

'add total
If counter1 = no_task Then
Cells(counter1 + 3, 1).Value = "Histogram Total"
Call histo_total(diff, no_task)
Call histo_shifter(diff, no_task)
Call histo_chart_build(no_task)
Call s_curve_values(diff, no_task)
Call s_curve_totals(diff, no_task)
Call s_curve_chart_build(no_task)
End If
Next counter
Next counter1
End Sub