Worksheet_SelectionChange with Select Method of Range Class Failed

electronictokwa

Board Regular
Joined
Oct 25, 2011
Messages
122
I have been working on this for a couple of days now. Two sheets (Main and VCards); based on what is clicked on the Main sheet, a named range will be copied and should be pasted on range D:J on the Main sheet. Here is my code so far:


Const iTocCOl As Integer = 2

Const NVIDIA_Quadro_2000Row As Integer = 3


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim iRow As Integer
iRow = ActiveCell.Row
If Not ActiveCell.Column = iTocCOl Then
Exit Sub
End If

Select Case iRow
Case NVIDIA_Quadro_2000Row
Columns("D:J").Clear
Application.Goto reference:="Quadro_2000"
GoTo Paste
Case Else
Exit Sub
End Select
Paste:
Selection.Copy
Range("A1:D50").Select
ActiveCell.PasteSpecial xlPasteAll
Application.CutCopyMode = False

End Sub

There is the error Select Method of Range Class Failed line Range("A1:D50").Select. Thanks in advance for any ideas!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.ScreenUpdating = False
    Dim iRow As Integer
    iRow = ActiveCell.Row
    If Not ActiveCell.Column = iTocCOl Then
        Exit Sub
    End If
    Select Case iRow
    Case NVIDIA_Quadro_2000Row
        Columns("D:J").Clear
        Application.Goto reference:="Quadro_2000"
        Selection.Copy Destination:=Range("a1:d50")
        Application.CutCopyMode = False
    Case Else
        Exit Sub
    End Select
End Sub
 
Upvote 0
Try this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.ScreenUpdating = False
    Dim iRow As Integer
    iRow = ActiveCell.Row
    If Not ActiveCell.Column = iTocCOl Then
        Exit Sub
    End If
    Select Case iRow
    Case NVIDIA_Quadro_2000Row
        Columns("D:J").Clear
        Application.Goto reference:="Quadro_2000"
        Selection.Copy Destination:=Range("a1:d50")
        Application.CutCopyMode = False
    Case Else
        Exit Sub
    End Select
End Sub

Tried this but the named range is still not copied. What I did was place all the named range on the same sheet and just hide them and my original code works. I am assuming the target range should be on the same sheet? I also tried declaring the sheet name on the Paste: section but the error persists.
 
Upvote 0

Forum statistics

Threads
1,226,237
Messages
6,189,801
Members
453,569
Latest member
Kevo85

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