+ Reply to Thread
Results 1 to 7 of 7

function that finds length of a table; Cannot run on a different sheet.

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Cool function that finds length of a table; Cannot run on a different sheet.

    Hi guys,

    The BlanksToSkip() code I use all the time and want to modify it, so it can work within the sub Sample().
    I have highlighted where it trips up. In the past I have had to use "Active.worksheet" before calling BlanksToSkip(). I would prefer to have a way for BlanksToSkip to work regardless, or maybe another parameter as the worksheet? whatever is best.

    Thanks!
    Jimmy

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

    It seems to work when I comment out the 'X2.Select. I think. thanks AlphaFrog. I still need to check something else though.

    Like there is another problem that's linked to this, but I am going to continue it on the related thread:
    https://www.excelforum.com/excel-pro...ml#post4807023


    ...
    I just tired this again, and I had to UNCOMMENT out the 'X2.Select to get it to work..
    So I problem is a bit of a weird one.
    Last edited by JimmyWilliams; 12-21-2017 at 09:29 AM.

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

    Re: function that finds length of a table; Cannot run on a different sheet.

    You can't select a range unles its parent sheet is active. Try this...

    Please Login or Register  to view this content.

    Or this...

    Please Login or Register  to view this content.

    Alternatively, you can write your code so that it doesn't select any ranges. Selection of a range is not required in your case.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: function that finds length of a table; Cannot run on a different sheet.

    Selecting ranges has very few practical uses but many reasons not to use it. As mentioned, you cant select a cell on an inactive sheet. Typically you can act upon a range or other object without needing to select it and without needing to change sheets.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  4. #4
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: function that finds length of a table; Cannot run on a different sheet.

    Thanks Zer0,

    Application.GoTo X2, seems to be working. for now..

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: function that finds length of a table; Cannot run on a different sheet.

    Out of curiosity, why are you using CallByName there?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: function that finds length of a table; Cannot run on a different sheet.

    Quote Originally Posted by xlnitwit View Post
    Out of curiosity, why are you using CallByName there?
    I haven't a clue. its been +6month since I wrote this bit, still using it but haven't looked at it. I'm sure I had a reason back when I first made it. Probably the only thing I could get working.
    If you know/think of something better, let me know!

    Jimmy

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: function that finds length of a table; Cannot run on a different sheet.

    I can't see any reason not to simply use
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Shorten string length if exceeds 31 characters (max sheet name length)
    By r2fro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2014, 05:57 AM
  2. Possible to link Table length to Pivot table length?
    By saber0091 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-04-2013, 05:36 PM
  3. Replies: 10
    Last Post: 08-15-2012, 10:20 AM
  4. [SOLVED] Run a function until it finds a blank cell
    By Leif Magnus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-14-2012, 02:01 PM
  5. Macro that finds word in table and reports all rows with data to new table
    By jermsalerms in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2007, 03:57 AM
  6. Help with code that finds a sheet's name
    By KimberlyC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2005, 06:05 PM
  7. need IF function to return 0 if it finds a one out of three words
    By aledger in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-28-2005, 09:06 PM

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