+ Reply to Thread
Results 1 to 8 of 8

Error code selecting block of data from worksheet

  1. #1
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Error code selecting block of data from worksheet

    Hi,

    I am trying to select a block of data from a remote worksheet but I keep on getting the following error

    Run time error '1004':
    Application-defined or object-defined error.

    I press the help button but I don't understand what they are trying to tell me.

    I have attached the file and I am working on worksheet 21 "PT Monthly Report 1"

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Error code selecting block of data from worksheet

    You'll have to active the worksheet first. But when you do, the worksheet_activate event runs switching sheets again.

    You'll need to get away from Selection, or do some other rewriting.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Error code selecting block of data from worksheet

    Thanks David, but I am a little confused. Which sheet do I have to activate? Do I end up in a loop?

    Thanks

    Dan

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Error code selecting block of data from worksheet

    Change in red.

    Please Login or Register  to view this content.
    Last edited by Tinbendr; 05-05-2014 at 09:10 AM.

  5. #5
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Error code selecting block of data from worksheet

    Thanks so much, I have one last question. My goal was to transfer the data from 'PT Treatments' worksheet to 'PT monthly Report-1' so I modified your 3rd line of code and changed 'select' to 'copy worksheets("PT Monthly Report-1").Range("E10") and it worked. My only problem now is that the active worksheet is 'PT Treatments' but I want it to be 'PT Monthly Report-1'. How can I make 'PT Monthly Report-1' the active (visible) worksheet without starting the whole subroutine all over again? I am new to VBA and not sure how to get around that problem.

    Thanks

    Dan

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Error code selecting block of data from worksheet

    without starting the whole subroutine all over again?
    Therein is the problem with Worksheet_activation and selection between sheets.

    You might be able to test if a certain condition exists at the top of the sub to see if the routine has been run already.

  7. #7
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Error code selecting block of data from worksheet

    The PT Treatment as well as OT Treatment and SLP Treatment are worksheets where time spent with patients is recorded. What I am trying to do on a monthly basis is to generate billing reports for the specific month of treatment. To do this I created worksheets (PT Monthly Report-1, etc.) that only show the billing period in question. The idea was when it was time to generate a billing report the PT Monthly Report-1 tab would be selected and when the billing report worksheet opened you would first see an input screen to enter the beginning billing date. That information would be used to determine the beginning and ending columns on the PT Treatment worksheet so the data could be copied and pasted into the PT Monthly Report-1 and then printed. The problem as you know is that I get stuck in a loop. Could you give me a suggestion as to how I should set this up? Should I just put a command button on the PT Monthly Report-1 worksheet and not initiate the subroutine off the activation command. Should I put the subroutine in a separate module? Any suggestions would be appreciated.

    Thanks!

    Dan

  8. #8
    Registered User
    Join Date
    04-20-2012
    Location
    Oneida, NY
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Error code selecting block of data from worksheet

    Never mind found another way to do it.

    Thanks

    Dan

+ 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] New Error/Old Code - Run Time Error 91; Object variable or With block variable not set
    By humboldtguy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-15-2014, 12:39 AM
  2. [SOLVED] Error in a Code. Object variable or With block variable not set????
    By ciapul12 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-03-2014, 12:20 PM
  3. [SOLVED] Excel VBA error code 91: Object variable or with block variable not set
    By wilnexpc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2013, 11:46 AM
  4. [SOLVED] vba macro code error: statement invalide outside type block
    By satania in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-20-2012, 04:05 PM
  5. code error while selecting a range-file attached
    By SMILE in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2011, 06:02 AM

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