+ Reply to Thread
Results 1 to 6 of 6

Method 'Range' error at running macro on Worksheet

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    Slovenia; Kranj
    MS-Off Ver
    Office 365
    Posts
    67

    Method 'Range' error at running macro on Worksheet

    Hi,

    I made macro, which does this ...

    When I run it, it check row and column of active/selected cell, than select range(s) from 5 cells above to 5 cells below and from 5 cells left to 5 cells right. So it looks like a cross with active/selected cell in the middle.

    Macro code is ...

    Please Login or Register  to view this content.
    Should I explain something? If...else...endif sentence under c = ActiveCell.Column change column number in to the letter. vrng = vertical range, hrng = horizontal range, ac = active cell ...

    So, if you run this code will work normally, as it should ... for now it is working just if active cell is more than 5 rows and 5 columns away from edge, but there is time for improvement ... I have a problem, I got error message Method range of object _Worksheet failed when I put this code in to the Worksheet object and SelectionChange procedure ...

    Please Login or Register  to view this content.
    Any idea how to resolve this or why this is not working? Oh yes, I need this, because I want that every time I'll select a cell (SelectionChange) this "selected cross" will appear.


    Thx in advance ... cheers, Marko
    Last edited by DiCaver; 02-22-2013 at 03:55 AM.
    IF a = b THEN
    GO "back to school"

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Method 'Range' error at running macro on Worksheet

    Ok

    basically your formula works as long as minimum column and minimum row are 6.

    either make your first three rows as follows:-

    Please Login or Register  to view this content.
    or if c or r are less then 6 exit your macro.
    Last edited by JBeaucaire; 02-22-2013 at 04:43 AM. Reason: Added code tags, as per forum rules. Don't forget!

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Method 'Range' error at running macro on Worksheet

    Try this...

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 02-19-2013 at 05:43 PM.

  4. #4
    Registered User
    Join Date
    01-26-2012
    Location
    Slovenia; Kranj
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Method 'Range' error at running macro on Worksheet

    Hi, this is working exactly that I was looking for! Thx!

    But I still have question, just for my knowledge, what is wrong with my way of doing it, that in Worksheet_SelectionChange I got this error message?

    Thx again ... cheers, Marko
    Last edited by arlu1201; 02-22-2013 at 04:43 AM. Reason: Do not quote whole posts.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Method 'Range' error at running macro on Worksheet

    Quote Originally Posted by DiCaver View Post
    Hi, this is working exactly that I was looking for! Thx!

    But I still have question, just for my knowledge, what is wrong with my way of doing it, that in Worksheet_SelectionChange I got this error message?

    Thx again ... cheers, Marko
    You're welcome.

    Your original code does work except for one thing. If you put your code as the Worksheet_SelectionChange procedure, the code itself makes a new selection change. When it selects more cells, it triggers the Worksheet_SelectionChange procedure again . From the newly selected cells it triggers the Worksheet_SelectionChange procedure yet again. It keeps triggering itself until it errors.

    Put something like this as the first line in your original code to exit if more than one cell is selected.
    If Target.Count > 1 Then Exit Sub

  6. #6
    Registered User
    Join Date
    01-26-2012
    Location
    Slovenia; Kranj
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Method 'Range' error at running macro on Worksheet

    Quote Originally Posted by AlphaFrog View Post
    Put something like this as the first line in your original code to exit if more than one cell is selected.
    If Target.Count > 1 Then Exit Sub
    OK, now understand and yes, putting above mentioned line at the beginning of my code, solve this error.

    Thx again, Marko

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1