Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:13:33+00:00 2026-05-27T23:13:33+00:00

I have some problems with a piece of code. I get an error when

  • 0

I have some problems with a piece of code. I get an error when it has to select a range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim valrand As Long
If Intersect(Target, ActiveCell) = "Insert line" Then
valrand = ActiveCell.Row
    If Worksheets("IR").Cells(valrand, 18).Value <> 5 Then
        Sheets("Format").Select
        MsgBox ("Format")
        Range("A13:N13").Select 'here's the error
        Selection.Copy

        Sheets("IR").Select
        Range("A" & valrand + 2 + Worksheets("IR").Cells(12, 18) & ":N" & valrand + 2 + Worksheets("IR").Cells(12, 18)).Select
        Selection.Insert Shift:=xlDown

        Range("A38:N38").Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp

        Range("A5").Select
        contor = Worksheets("IR").Cells(12, 18).Value + 1
        Worksheets("IR").Cells(12, 18).Value = contor
    End If
End If
End Sub

Where I put the commet “here’s the error” it gives me “Select method of Range class failed”
What am I doing wrong? Usually this piece of code worked before I added in the SelectionChange code block.
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:13:34+00:00Added an answer on May 27, 2026 at 11:13 pm

    You should look at avoiding Select when using Sheet code (best to avoid it altogether, more later on this) and use something like this instead

    Application.Goto Sheets("Format").Range("A13:N13")
    

    (I had tried fully qualifying the reference but this only worked if I used

       Sheets("Format").Select
       Sheets("Format").Range("A13:N13").Select
    

    which is clearly overkill)

    While that solves you immediate issue you should look at consolidating your code, for example

    1. Disabling Events so that other sheet events dont fire while your Select is running
    2. Removing any Select statements

    This is an example of what may work better (now with no sheet activation)

     Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim ws1 As Worksheet
        Dim ws2 As Worksheet
        Dim lngRand As Long
        Dim rng1 As Range
        Set ws1 = Sheets("Format")
        Set ws2 = Sheets("IR")
        If Intersect(Target, ActiveCell) = "Insert line" Then
            lngRand = ActiveCell.Row
            If ws2.Cells(lngRand, 18).Value <> 5 Then
                Application.EnableEvents = False
                Set rng1 = Range("A" & lngRand + 2 + ws2.Cells(12, 18))
                'extend rng1 from column A to colum N
                Set rng1 = rng1.Resize(rng1.Rows.Count, 14)
                ws2.Range(rng1.Address).Insert xlDown
                'copy Format to IR
                ws1.Range("A13:N13").Copy ws2.Range(rng1.Address)
                'Update Format
                ws2.Range("A38:N38").Delete Shift:=xlUp
                ws2.Cells(12, 18).Value = ws2.Cells(12, 18).Value + 1
                Application.EnableEvents = True
            End If
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problems sending an id though jquery. I have a form select
I have the following piece of code, which when I compile it, I get:
I have some piece of code which goes like this: pipe(fd); child_map[0] = fd[0];
I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I
I have some problems on a site with the concurrent access to a list.
I have some problems sending mails through SMTP using Spring's MailSender interface and the
I have some problems with OpenCV s cvCanny(...) and the Image data types it
i have some problems with rowspan: var doc1 = new Document(); doc1.SetPageSize(PageSize.A4.Rotate()); string path
I am just starting Java RMI and have some problems with when to use
I am very new to C and I have some problems learning about pointers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.