Error in VBA Code

ameya

Board Regular
Joined
Jun 10, 2014
Messages
105
I am getting the "object does not support this property or method error" (Run Time error 438) in the bolded line below. Any reasons as to why this does not work?

Code:
Dim rInitialDate As Range, rFinalDate As Range, rDateRange As Range, Calculation As Worksheet
    
With Worksheets("Calculation")
    [B]Set rInitialDate = .Find(What:=DateValue(InitialDate), After:=.Cells(1, 5), LookIn:=xlFormulas, LookAt:=xlWhole, SearchDirection:=xlNext, SearchFormat:=False)[/B]
    Set rFinalDate = .Find(What:=DateValue(FinalDate), After:=.Cells(1, 5), LookIn:=xlFormulas, LookAt:=xlWhole, SearchDirection:=xlPrevious, SearchFormat:=False)
    If rInitialDate Is Nothing Or rFinalDate Is Nothing Then
        MsgBox "Not able to find both dates"
    Else
        Set rDateRange = .Range(rInitialDate, rFinalDate)
    End If
End With
Dim startRow As Integer, endRow As Integer, rDateRangeIndex As Integer, rOEERange As Range
startRow = rInitialDate.Row
endRow = rFinalDate.Row
With Worksheets("Calculation")
    Set startOEECell = .Cells(startRow, 45)
    Set endOEECell = .Cells(endRow, 45)
    Set rOEERange = .Range(startOEECell, endOEECell)
End With
'to create new Range to reflect MC,Shift,Date
With Worksheets("Calculation")
    For i = startRow To endRow Step 1
        If Cells(i, 7) Is Not MC.Value Or Cells(i, 6) Is Not Shift.Value _
            Or DateValue(rDateRange(i - (startRow - 1))) < DateValue(InitialDate) _
            Or DateValue(rDateRange(i - (startRow - 1))) > DateValue(FinalDate) Then
                rDateRange(i - (startRow - 1)).Delete
                rOEERange(i - (startRow - 1)).Delete
        End If
    Next i
End With
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I changed part of the for loop to reflect the actual values in the cells.

Code:
If .Cells(i, 7) <> MC.Value Or .Cells(i, 6) <> Shift.Value _
            Or DateValue(rDateRange.Cells((i - (startRow - 1)))).Value > DateValue(FinalDate.Value) _
            Or DateValue(rDateRange.Cells((i - (startRow - 1)))).Value < DateValue(InitialDate.Value) Then

Here, I'm getting an error in the debugger saying "Object Required". Any ideas how to fix this?
 
Upvote 0
Also changed .Cells(i, 7) to .Cells(i, 7).value
and corrected the parantheses around date value. still nothing though.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top