N
Naji
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 = ""
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 = ""