fluxcapacitr609
New Member
- Joined
- Feb 21, 2018
- Messages
- 24
I'm trying to clean up my code. I want to change how I compare dates. It works when I type in the date, but when I declare a function and set it to a date, it doesn't work.
Working Code
Not working
I'm sure it's something small I'm missing but any help would be greatly appreciated.
Working Code
Code:
Sub TestMod()
'.......................................................
Dim LastRow As Long
Dim erow As Long
Dim i As Long
Dim strComponent
Dim strVessel
Dim intOil As Long
Dim myCell
Dim bcheck As Boolean
Dim lwRng ' experimental lower date
Dim hgRng ' experimental upper date
LastRow = Sheet1.Cells(Rows.count, 1).End(xlUp).Row
Sheet1.Select
Range("A1").Select
'January
On Error Resume Next
bcheck = Evaluate("isref(Jan_2018!A1)")
If bcheck Then
Set myCell = Sheets("Jan_2018")
lwRng = "2018-1-1"
hgRng = "2018-1-32"
'Cape Henlopen, Crossings
For i = 2 To LastRow
mydate = Cells(i, 3)
strVessel = Cells(i, 1)
strComponent = Cells(i, 2)
If InStr(1, strComponent, "Number of Crossings") And InStr(1, strVessel, "Cape Henlopen") And mydate >= "2018-1-1" And mydate <= "2018-1-32" Then
erow = Day(mydate) + 3
Cells(i, 4).Copy Destination:=myCell.Range("J" & erow)
End If
Next i
end sub
Not working
Code:
Sub TestMod()
'.......................................................
Dim LastRow As Long
Dim erow As Long
Dim i As Long
Dim strComponent
Dim strVessel
Dim intOil As Long
Dim myCell
Dim bcheck As Boolean
Dim lwRng ' experimental lower date
Dim hgRng ' experimental upper date
LastRow = Sheet1.Cells(Rows.count, 1).End(xlUp).Row
Sheet1.Select
Range("A1").Select
'January
On Error Resume Next
bcheck = Evaluate("isref(Jun_2018!A1)")
If bcheck Then
Set myCell = Sheets("Jun_2018")
lwRng = "2018-6-1"
hgRng = "2018-6-32"
'Cape Henlopen, Crossings
For i = 2 To LastRow
mydate = Cells(i, 3)
strVessel = Cells(i, 1)
strComponent = Cells(i, 2)
If InStr(1, strComponent, "Number of Crossings") And InStr(1, strVessel, "Cape Henlopen") And mydate >= lwRng And mydate <= hgRng Then
erow = Day(mydate) + 3
Cells(i, 4).Copy Destination:=myCell.Range("J" & erow)
End If
Next i
end sub
I'm sure it's something small I'm missing but any help would be greatly appreciated.