Hi all, thank you for taking the time to read this.
I am currently working on a code in which an engine can be running in four possible states: On, Off, Automatic and Manual. I am trying to find the total number of hours it is running in manual. The code is as follows:
'START'
Dim run_time As Date
Dim stop_time As Date
Dim auto_time As Date
Dim man_time As Date
Dim man_time_new As Date
Dim total_man_time As Date
Dim row As Integer
Dim col As Integer
Sub Calc()
Dim Sheet1 As Worksheet
Set Sheet1 = ALM.xlxm("Sheet1")
row = 1
total_man_time = 0
Do While row <= 60
col = 1
If Cells(row, col + 3) = "A-Engine Status COS RUN" Then
run_time = Cells(row, col) + Cells(row, col + 1)
ElseIf Cells(row, col + 3) = "A-Engine Status COS STOP" Then
stop_time = Cells(row, col) + Cells(row, col + 1)
ElseIf Cells(row, col + 3) = "A-Auto/Man Status COS AUTO" Then
auto_time = Cells(row, col) + Cells(row, col + 1)
ElseIf Cells(row, col + 3) = "A-Auto/Man Status COS MAN" Then
man_time = Cells(row, col) + Cells(row, col + 1)
End If
If Cells(row - 1, col + 3) = "A-Engine Status COS RUN" Then
total_man_time = total_man_time + man_time - run_time
ElseIf Cells(row - 1, col + 3) = "A-Engine Status COS STOP" Then
total_man_time = total_man_time
ElseIf Cells(row - 1, col + 3) = "A-Auto/Man Status COS AUTO" Then
total_man_time = total_man_time + man_time - auto_time
ElseIf Cells(row - 1, col + 3) = "A-Auto/Man Status COS MAN" Then
man_time_new = Cells(row, col) + Cells(row, col + 1)
total_man_time = total_man_time + man_time_new - man_time
Else
total_man_time = total_man_time
End If
row = row + 1
Loop
End Sub
Sub FindingLastRow()
'PURPOSE: Different ways to find the last row number of a range
'SOURCE: Squarespace - Claim This Domain
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ALM.xlxm("Sheet1")
'Ctrl + Shift + End
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).row
End Sub
'END'
When I run this code, I get a Runtime Error 424, indicating that an Object is required. Please excuse my ignorance, but I have never worked with VBA before. I was wondering what this error means and how I can fix it.
Thanks for your help!
I am currently working on a code in which an engine can be running in four possible states: On, Off, Automatic and Manual. I am trying to find the total number of hours it is running in manual. The code is as follows:
'START'
Dim run_time As Date
Dim stop_time As Date
Dim auto_time As Date
Dim man_time As Date
Dim man_time_new As Date
Dim total_man_time As Date
Dim row As Integer
Dim col As Integer
Sub Calc()
Dim Sheet1 As Worksheet
Set Sheet1 = ALM.xlxm("Sheet1")
row = 1
total_man_time = 0
Do While row <= 60
col = 1
If Cells(row, col + 3) = "A-Engine Status COS RUN" Then
run_time = Cells(row, col) + Cells(row, col + 1)
ElseIf Cells(row, col + 3) = "A-Engine Status COS STOP" Then
stop_time = Cells(row, col) + Cells(row, col + 1)
ElseIf Cells(row, col + 3) = "A-Auto/Man Status COS AUTO" Then
auto_time = Cells(row, col) + Cells(row, col + 1)
ElseIf Cells(row, col + 3) = "A-Auto/Man Status COS MAN" Then
man_time = Cells(row, col) + Cells(row, col + 1)
End If
If Cells(row - 1, col + 3) = "A-Engine Status COS RUN" Then
total_man_time = total_man_time + man_time - run_time
ElseIf Cells(row - 1, col + 3) = "A-Engine Status COS STOP" Then
total_man_time = total_man_time
ElseIf Cells(row - 1, col + 3) = "A-Auto/Man Status COS AUTO" Then
total_man_time = total_man_time + man_time - auto_time
ElseIf Cells(row - 1, col + 3) = "A-Auto/Man Status COS MAN" Then
man_time_new = Cells(row, col) + Cells(row, col + 1)
total_man_time = total_man_time + man_time_new - man_time
Else
total_man_time = total_man_time
End If
row = row + 1
Loop
End Sub
Sub FindingLastRow()
'PURPOSE: Different ways to find the last row number of a range
'SOURCE: Squarespace - Claim This Domain
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ALM.xlxm("Sheet1")
'Ctrl + Shift + End
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).row
End Sub
'END'
When I run this code, I get a Runtime Error 424, indicating that an Object is required. Please excuse my ignorance, but I have never worked with VBA before. I was wondering what this error means and how I can fix it.
Thanks for your help!