Method Range of Object Global Failed

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am receiving the "Method Range of Object Global Failed" error on the line below.

Code:
Range1 = Range(StartDate1, EndDate1)

I have "StartDate1" and "EndDate1" included in the watch window and both are showing date values as they should be.

I would like "Range1" to include a set of date values from StartDate1 to EndDate1. Is this the correct method to go about accomplishing something like this?

The line above exists within the context below:

Code:
Dim bb As Integer:          bb = Range("C5").End(xlDown).RowDim dd As Integer:          dd = 1
Dim StartDate1 As Date
Dim EndDate1 As Date
Dim StartDate2 As Date
Dim EndDate2 As Date
Dim Range1 As Range
Dim Range2 As Range
Dim TestVar As Range


Do Until bb = 5


    StartDate1 = Cells(bb, 4)
    EndDate1 = Cells(bb, 5)
    Range1 = Range(StartDate1, EndDate1)
    
    Do Until bb - dd = 5
    
        StartDate2 = Cells(bb - dd, 4)
        EndDate2 = Cells(bb - dd, 5)
        Range2 = Range(StartDate2, EndDate2)
        
        TestVar = Application.Union(Range1, Range2)
        
        If TestVar <> "" Then
        
        Rows(bb).EntireRow.Delete
        
        Exit Do
    
        Else: dd = dd - 1
    
        End If
    
        Loop
        
bb = bb - 1
 
Loop
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
The error is expected,. The range object cant pick up values from those dates

If for example startdate is 1-jan-2018 and enddate if 1-feb-2018, you could do something like

You could use a For loop to add values between those values to a range of cells. then finally Set Range1 to be equal to that range
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

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