Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Naji
 
Posts: n/a
Default Figuring out loop for a production schedule

There is probably a simple solution to this, but everything I've tried
doesn't work. So, I have a spreadsheet file that looks through a
scheduling spreadsheet looking for X's and Blank spots to indicate up
or downtime. It reads the information and then writes it into a CSV
file. Right now the loop ends when the Unit number is blank and it
reads everything else. I need it to skip certain unit numbers. For
example, I want it to go through all the schedules and only worry about
writing units 86 and 10 and a couple others into a CSV file, bypassing
other irrelevant unit numbers. How would you do this ? Here is the code
I have:

Private Function CreateSCV( _
sh As Worksheet, _
StartingDateRange As Range, _
FileNumber As Integer) As Boolean

Dim UnitNumber As String, CurrentDate As Date
Dim DataRange As Range
Dim FirstColumn As Integer, LastColumn As Integer, CurrentColumn As
Integer
Dim ShiftRow As Long, ShiftStatus(1 To 3) As String
Dim ShiftItem As Integer
Dim PreviousShiftStatus As String, CurrentShiftStatus As String
Dim ConservationShutdown As Boolean

Set DataRange = sh.Range(StartingDateRange.Offset(1), _
StartingDateRange.End(xlToRight).Offset(3))

FirstColumn = DataRange(1).Column
LastColumn = FirstColumn + DataRange.Columns.Count - 1
ShiftRow = DataRange(1).Row
UnitNumber = DataRange(1).Offset(, -2)
CurrentDate = DateValue(StartingDateRange)

Do

PreviousShiftStatus = "No Previous Status"

For CurrentColumn = FirstColumn To LastColumn

ShiftStatus(1) = sh.Cells(ShiftRow, CurrentColumn)
ShiftStatus(2) = sh.Cells(ShiftRow + 1, CurrentColumn)
ShiftStatus(3) = sh.Cells(ShiftRow + 2, CurrentColumn)

For ShiftItem = 1 To 3
ConservationShutdown = False

If Not ShiftStatus(ShiftItem) Like "[XEO]" Then
If Len(Trim(ShiftStatus(ShiftItem))) < 0 Then
sh.Cells(ShiftRow + (ShiftItem - 1),
CurrentColumn).Select
Stop
'problem with range sh.Cells(ShiftRow +
(ShiftItem -1), CurrentColumn)
'raise error, notify user and select the
problem range, exit
End If
End If

Select Case Trim(UCase(ShiftStatus(ShiftItem)))
Case "X", "O"
CurrentShiftStatus = "UP"
Case ""
CurrentShiftStatus = "DOWN"
Case "E"
CurrentShiftStatus = "DOWN"
ConservationShutdown = True
End Select

If PreviousShiftStatus < CurrentShiftStatus Then
'status changed
If ConservationShutdown Then
Print #FileNumber, " " & UnitNumber & "," &
"DOWN" & "," & _
Format(CurrentDate + #12:00:00 PM#,
"mm/dd/yyyy hh:mm")
Print #FileNumber, " " & UnitNumber & "," &
"UP" & "," & _
Format(CurrentDate + #6:00:00 PM#,
"mm/dd/yyyy hh:mm")
CurrentShiftStatus = "UP"
Else
Print #FileNumber, " " & UnitNumber & "," &
CurrentShiftStatus & "," & _
Format(CurrentDate + Choose(ShiftItem,
#12:00:00 AM#, #8:00:00 AM#, #4:00:00 PM#), _
"mm/dd/yyyy hh:mm")
End If
End If

PreviousShiftStatus = CurrentShiftStatus
Next

CurrentDate = CurrentDate + 1

Next

Set DataRange = DataRange.Offset(6)
UnitNumber = DataRange(1).Offset(, -2)
ShiftRow = DataRange(1).Row
CurrentDate = StartingDateRange
Loop Until UnitNumber = ""

  #2   Report Post  
Naji
 
Posts: n/a
Default Figuring out loop for a production schedule


Naji wrote:
There is probably a simple solution to this, but everything I've tried
doesn't work. So, I have a spreadsheet file that looks through a
scheduling spreadsheet looking for X's and Blank spots to indicate up
or downtime. It reads the information and then writes it into a CSV
file. Right now the loop ends when the Unit number is blank and it
reads everything else. I need it to skip certain unit numbers. For
example, I want it to go through all the schedules and only worry about
writing units 86 and 10 and a couple others into a CSV file, bypassing
other irrelevant unit numbers. How would you do this ? Here is the code
I have:

Private Function CreateSCV( _
sh As Worksheet, _
StartingDateRange As Range, _
FileNumber As Integer) As Boolean

Dim UnitNumber As String, CurrentDate As Date
Dim DataRange As Range
Dim FirstColumn As Integer, LastColumn As Integer, CurrentColumn As
Integer
Dim ShiftRow As Long, ShiftStatus(1 To 3) As String
Dim ShiftItem As Integer
Dim PreviousShiftStatus As String, CurrentShiftStatus As String
Dim ConservationShutdown As Boolean

Set DataRange = sh.Range(StartingDateRange.Offset(1), _
StartingDateRange.End(xlToRight).Offset(3))

FirstColumn = DataRange(1).Column
LastColumn = FirstColumn + DataRange.Columns.Count - 1
ShiftRow = DataRange(1).Row
UnitNumber = DataRange(1).Offset(, -2)
CurrentDate = DateValue(StartingDateRange)

Do

PreviousShiftStatus = "No Previous Status"

For CurrentColumn = FirstColumn To LastColumn

ShiftStatus(1) = sh.Cells(ShiftRow, CurrentColumn)
ShiftStatus(2) = sh.Cells(ShiftRow + 1, CurrentColumn)
ShiftStatus(3) = sh.Cells(ShiftRow + 2, CurrentColumn)

For ShiftItem = 1 To 3
ConservationShutdown = False

If Not ShiftStatus(ShiftItem) Like "[XEO]" Then
If Len(Trim(ShiftStatus(ShiftItem))) < 0 Then
sh.Cells(ShiftRow + (ShiftItem - 1),
CurrentColumn).Select
Stop
'problem with range sh.Cells(ShiftRow +
(ShiftItem -1), CurrentColumn)
'raise error, notify user and select the
problem range, exit
End If
End If

Select Case Trim(UCase(ShiftStatus(ShiftItem)))
Case "X", "O"
CurrentShiftStatus = "UP"
Case ""
CurrentShiftStatus = "DOWN"
Case "E"
CurrentShiftStatus = "DOWN"
ConservationShutdown = True
End Select

If PreviousShiftStatus < CurrentShiftStatus Then
'status changed
If ConservationShutdown Then
Print #FileNumber, " " & UnitNumber & "," &
"DOWN" & "," & _
Format(CurrentDate + #12:00:00 PM#,
"mm/dd/yyyy hh:mm")
Print #FileNumber, " " & UnitNumber & "," &
"UP" & "," & _
Format(CurrentDate + #6:00:00 PM#,
"mm/dd/yyyy hh:mm")
CurrentShiftStatus = "UP"
Else
Print #FileNumber, " " & UnitNumber & "," &
CurrentShiftStatus & "," & _
Format(CurrentDate + Choose(ShiftItem,
#12:00:00 AM#, #8:00:00 AM#, #4:00:00 PM#), _
"mm/dd/yyyy hh:mm")
End If
End If

PreviousShiftStatus = CurrentShiftStatus
Next

CurrentDate = CurrentDate + 1

Next

Set DataRange = DataRange.Offset(6)
UnitNumber = DataRange(1).Offset(, -2)
ShiftRow = DataRange(1).Row
CurrentDate = StartingDateRange
Loop Until UnitNumber = ""





Anyone? Is this not possible or just nobody replied? I need it to loop
from beginning until end, and in addition to filter out certain unit
numbers. Any help or direction would be greatly appreciated!

  #3   Report Post  
exceluserforeman
 
Posts: n/a
Default Figuring out loop for a production schedule

Hi,

Set DataRange = sh.Range(StartingDateRange.Offset(1), _
This part StartingDateRange.End(xlToRight).Offset(3))
xlToRight only goes as far as data is in each cell. then Offset(3) ,
I am not sure maybe offset(0,3) is better but when a blank cell is reached
you then jump 3 columns to the right?

You can send me all details on what you want done and I can maybe create a
userform utility for you.

You can see my Excel stuff at:

http://www.geocities.com/excelmarksway

Why do you write it to a CSV? Where does it go to as a CSV file? Maybe ACCESS?

- mark

"Naji" wrote:

There is probably a simple solution to this, but everything I've tried
doesn't work. So, I have a spreadsheet file that looks through a
scheduling spreadsheet looking for X's and Blank spots to indicate up
or downtime. It reads the information and then writes it into a CSV
file. Right now the loop ends when the Unit number is blank and it
reads everything else. I need it to skip certain unit numbers. For
example, I want it to go through all the schedules and only worry about
writing units 86 and 10 and a couple others into a CSV file, bypassing
other irrelevant unit numbers. How would you do this ? Here is the code
I have:

Private Function CreateSCV( _
sh As Worksheet, _
StartingDateRange As Range, _
FileNumber As Integer) As Boolean

Dim UnitNumber As String, CurrentDate As Date
Dim DataRange As Range
Dim FirstColumn As Integer, LastColumn As Integer, CurrentColumn As
Integer
Dim ShiftRow As Long, ShiftStatus(1 To 3) As String
Dim ShiftItem As Integer
Dim PreviousShiftStatus As String, CurrentShiftStatus As String
Dim ConservationShutdown As Boolean

Set DataRange = sh.Range(StartingDateRange.Offset(1), _
StartingDateRange.End(xlToRight).Offset(3))

FirstColumn = DataRange(1).Column
LastColumn = FirstColumn + DataRange.Columns.Count - 1
ShiftRow = DataRange(1).Row
UnitNumber = DataRange(1).Offset(, -2)
CurrentDate = DateValue(StartingDateRange)

Do

PreviousShiftStatus = "No Previous Status"

For CurrentColumn = FirstColumn To LastColumn

ShiftStatus(1) = sh.Cells(ShiftRow, CurrentColumn)
ShiftStatus(2) = sh.Cells(ShiftRow + 1, CurrentColumn)
ShiftStatus(3) = sh.Cells(ShiftRow + 2, CurrentColumn)

For ShiftItem = 1 To 3
ConservationShutdown = False

If Not ShiftStatus(ShiftItem) Like "[XEO]" Then
If Len(Trim(ShiftStatus(ShiftItem))) < 0 Then
sh.Cells(ShiftRow + (ShiftItem - 1),
CurrentColumn).Select
Stop
'problem with range sh.Cells(ShiftRow +
(ShiftItem -1), CurrentColumn)
'raise error, notify user and select the
problem range, exit
End If
End If

Select Case Trim(UCase(ShiftStatus(ShiftItem)))
Case "X", "O"
CurrentShiftStatus = "UP"
Case ""
CurrentShiftStatus = "DOWN"
Case "E"
CurrentShiftStatus = "DOWN"
ConservationShutdown = True
End Select

If PreviousShiftStatus < CurrentShiftStatus Then
'status changed
If ConservationShutdown Then
Print #FileNumber, " " & UnitNumber & "," &
"DOWN" & "," & _
Format(CurrentDate + #12:00:00 PM#,
"mm/dd/yyyy hh:mm")
Print #FileNumber, " " & UnitNumber & "," &
"UP" & "," & _
Format(CurrentDate + #6:00:00 PM#,
"mm/dd/yyyy hh:mm")
CurrentShiftStatus = "UP"
Else
Print #FileNumber, " " & UnitNumber & "," &
CurrentShiftStatus & "," & _
Format(CurrentDate + Choose(ShiftItem,
#12:00:00 AM#, #8:00:00 AM#, #4:00:00 PM#), _
"mm/dd/yyyy hh:mm")
End If
End If

PreviousShiftStatus = CurrentShiftStatus
Next

CurrentDate = CurrentDate + 1

Next

Set DataRange = DataRange.Offset(6)
UnitNumber = DataRange(1).Offset(, -2)
ShiftRow = DataRange(1).Row
CurrentDate = StartingDateRange
Loop Until UnitNumber = ""


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
Create patient schedule based on master therapist schedule PapaBear Excel Discussion (Misc queries) 8 October 12th 05 04:56 AM
Production CLock Thorrrr Excel Worksheet Functions 0 May 2nd 05 06:00 PM
percentage of production against quotation Nigel Excel Discussion (Misc queries) 3 April 22nd 05 02:34 PM
Formating Dates for production schedule dpl7579 Excel Discussion (Misc queries) 1 January 11th 05 08:43 PM
RAW MATERIALS SCHEDULE Julian Campbell Excel Worksheet Functions 1 December 2nd 04 03:59 AM


All times are GMT +1. The time now is 05:25 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"