Run Time Error 424 Object required

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I was advised a very good code by @RoryA & decided to use it again.
I have changed worksheet names & copy / paste columns etc but im getting a RTE of 424 OBJECT REQUIRED when i run it.
Can you point me in the direction of finding the cause please

This is the code in use shown below

Rich (BB code):
Private Sub Kdx2_Click()
    
    Dim WB As Workbook, DestWB As Workbook
    Dim ws As Worksheet, DestWS As Worksheet
    Dim rng As Range, rngDest As Range
    Dim ColArr As Variant, SCol As Variant, DCol As Variant
 
    On Error Resume Next
    Set DestWB = Application.Workbooks("CLONING-KDX2.xlsm")

    If DestWB Is Nothing Then
        Workbooks.Open fileName:="C:\Users\Ian\Desktop\REMOTES ETC\DR\EXCEL WORKSHEETS\CLONING-KDX2.xlsm"
        Set DestWB = Application.Workbooks("CLONING-KDX2.xlsm")
    End If
    On Error GoTo 0

    Set WB = ThisWorkbook
    On Error Resume Next
    Set ws = WB.Worksheets("DATABASE")
    On Error GoTo 0
    If ws Is Nothing Then
        MsgBox "Worksheet 'DATABASE' IS MISSING"
        Exit Sub
    End If
 
    Set DestWS = DestWB.Worksheets("CLONING")
    ColArr = Array("A:A", "D:B", "G:C", "N:D", "M:E", "L:F", "I:G")
    Dim DestNextRow As Long
    With DestWS
        If IsEmpty(.Range("A" & 1)) Then
            DestNextRow = 1
        Else
            DestNextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        End If
    End With

    Application.ScreenUpdating = False
    For Each SCol In ColArr
        DCol = Split(SCol, ":")(1)
        SCol = Split(SCol, ":")(0)
        With ws
            Set rng = .Cells(Target.Row, SCol)
        End With

        With DestWS
            Set rngDest = .Range(DCol & DestNextRow)
        End With
        rng.Copy
        rngDest.PasteSpecial PASTE:=xlPasteValues
        
        rngDest.Borders.Weight = xlThin
        rngDest.Font.Size = 16
        rngDest.Font.Bold = True
        rngDest.HorizontalAlignment = xlCenter
        rngDest.Cells.Interior.ColorIndex = 6
        rngDest.Cells.RowHeight = 25
    Next SCol
    Application.ScreenUpdating = True
   
 
With ActiveWorkbook ' THIS WILL SAVE & CLOSE CLONING-KDX2 WORKBOOK
   .Save
   .Saved = True
   .Close
End With

End Sub
 
Add the 3 lines in red, run the code, what do the 3 message boxes state?

Rich (BB code):
        SCol = Split(SCol, ":")(0)
        
        MsgBox ActiveCell.Row
        MsgBox "'" & ActiveCell.Parent.Name & "'!" & ActiveCell.Address(External:=False)
        
        With ws
            Set rng = .Cells(ActiveCell.Row, SCol)
        End With

        With DestWS
            Set rngDest = .Range(DCol & DestNextRow)
        End With
        
        MsgBox rng.Address
        
        rng.Copy
        rngDest.PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Red lines added and as follows
15
KDX2LIST$A$15
SA$15

Pressing OK then does the same but 15 value becomes 8 followed by B,C,D etc etc
So same as above etc

8
KDX2LIST$B$8
SB$8

8
KDX2LIST$C$8
SC$8

And so on
 
Upvote 0
Then your activecell.row is changing probably because your ActiveCell is on Sheet KDX2LIST and it should be cell A6 on sheet DATABASE if you are using ActiveCell, as that is the sheet ws is set as.

Why not just use 6 rather than Activecell.row as you already know the row is 6?
 
Upvote 0
Solution
Yes using ActiveCell
So can this be fixed or should i wait for the member who advised the original code which when i see run flies through it.
 
Upvote 0
That did the trick,i just selected one you advised.
Changing it to 6 worked.

Should i start a new post for only allowing it to run if A6 is active ?
 
Upvote 0
VBA Code:
    If ActiveSheet.Name = "DATABASE" And ActiveCell.Address = "$A$6" Then

        With ws
            Set rng = .Cells(6, SCol)
        End With

        With DestWS
            Set rngDest = .Range(DCol & DestNextRow)
        End With

        rng.Copy
        rngDest.PasteSpecial Paste:=xlPasteValues
        
    
        ' + WHATEVER OTHER CODE YOU WANT TO RUN
       
    Else
        MsgBox "Yu Must Select Cell A6"
        Exit Sub
       
    End If
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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