End_Row = Range("A" & Rows.Count).End(xlUp).Row

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Consider the code below:

Rich (BB code):
Sub Move_Diamonds()
    
    Dim rngToCopy As Range
    Dim End_Row As Range
    Dim llastrow As Long
    Dim lcopyrows As Long
    lcopyrows = 0
    llastrow = 0
    With Workbooks("Rental_Main.xls").Worksheets("CLASS_Data")
         If .FilterMode Then .ShowAllData
         llastrow = Range("A65536").End(xlUp).Row
         MsgBox ("The Last Row Is: ") & llastrow
         With .Range("A1:J" & llastrow)
            .AdvancedFilter _
                    Action:=xlFilterInPlace, _
                    CriteriaRange:=Worksheets("Criteria").Range("D4:D5"), _
                    Unique:=False
            Set rngToCopy = .Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
            lcopyrows = rngToCopy.Count
            MsgBox ("Diamonds Found To Relocate: ") & lcopyrows
            If lcopyrows = 0 Then
                MsgBox ("There are NO diamonds found.")
            End If
            Workbooks("SportsOps.xls").Worksheets("MAIN").Range("D22").Value = lcopyrows
  
        End With
 
        If .FilterMode Then .ShowAllData
    End With

   If Not rngToCopy Is Nothing Then rngToCopy.EntireRow.Copy Destination:=Workbooks("Rental_Main.xls").Worksheets("Diamonds_Regular").Range("A2")
   End_Row = Range("A" & Rows.Count).End(xlUp).Row
   Range("K2:K" & End_Row).Formula = "=VLOOKUP(CONCATENATE(C2,D2),FACILITIES!$A$1:$B$100,2,FALSE)"
   With Application

        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
    End With
        
End Sub

I am receiving an error (Run Time Error. Object variable or With Block variable not set) with the highlighted red line.

Where have I messed up?

Jenn
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You've declared End_Row as a range, but are using End_Row = (number)

Try Dim End_Row As Long instead
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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