+ Reply to Thread
Results 1 to 8 of 8

button is being creating 2 rows above

  1. #1
    Registered User
    Join Date
    09-28-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    21

    button is being creating 2 rows above

    The following was working perfectly until now (It is now past 2000 rows - I don't believe this to affect anything, but I am mentioning it just for background info.)

    The following is called from another module where dCol = Column Letter; dCounter = Row Number.
    Please Login or Register  to view this content.

    Here is the createButton():
    Please Login or Register  to view this content.

    During my debugging, I verified the following:
    1) The range "r" that is received in createButton is the correct range. (Returns the value at that range when called through msgbox)
    2) When button.add is being executed, the "r" is still the correct range. (Returns the value at that range when called through msgbox)
    3) When the button is actually created, it shows up 2 rows above where it was told to be created. (Why is this happening is my question.)
    4) Errors occur because when the rest of the code is trying to change the label of the button, the button is not in the correct location - because it's 2 rows above.

    Thank you for any help!

    I had to do a workaround and it does work, but it is definitely NOT a robust fix. Here it is:
    Please Login or Register  to view this content.
    Last edited by GunNam; 11-27-2010 at 02:34 PM. Reason: Added more detail on 1) and 2) - when called through msgbox

  2. #2
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: button is being creating 2 rows above

    Hi

    Why would the position of the button affect the naming as that is done via "With selection" and the placement on the page is not an issue? Are your global variables correct?

    The command buttons.add leaves the new button selected, or should do, if you step through the macro is the button deselected for some reason?

    Regards

    Jeff
    Last edited by solnajeff; 11-27-2010 at 03:56 PM.

  3. #3
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: button is being creating 2 rows above

    Hi

    I have tried to reproduce your problem using values for dcol and dcounter but it always comes out correctly and without the actual sheet it is difficult to determine the problem.

    Perhaps you could 'sanitise' the relevant part of your workbook and post it for us to have a look at it.

    Regards

    Jeff

  4. #4
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,230

    Re: button is being creating 2 rows above

    I note that the cell argument being passed is on the Active Sheet (unqulaified Range)

    I also see that the button is being created on dSht (not nessesarily the same sheet as r)

    I see two fixes (depending on what you want)

    This will put the button on the same sheet as r.
    Please Login or Register  to view this content.
    This will put the button on Sheet("Dashboard") one cell left of the same cell as r.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    09-28-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: button is being creating 2 rows above

    Quote Originally Posted by solnajeff View Post
    Hi

    Why would the position of the button affect the naming as that is done via "With selection" and the placement on the page is not an issue? Are your global variables correct?

    The command buttons.add leaves the new button selected, or should do, if you step through the macro is the button deselected for some reason?
    Hi Jeff,

    After I edited the code from mikerickson's reply, I no longer get an error when I'm trying to change the label of the button, but the button is being created in the wrong cell.

    I stepped through the macro, and it IS selected after creation, and is being correctly labeled (no more errors thrown), except for where it is located.

    I have no global variables set.

    Here is what my code looks now (adjusted as recommended from mikerickson)
    Please Login or Register  to view this content.

    I uploaded a snapshot of where exactly the button is being created. It SHOULD be created left adjacent of "LB1019180"
    Attached Images Attached Images

  6. #6
    Registered User
    Join Date
    09-28-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: button is being creating 2 rows above

    Quote Originally Posted by mikerickson View Post
    I note that the cell argument being passed is on the Active Sheet (unqulaified Range)

    I also see that the button is being created on dSht (not nessesarily the same sheet as r)

    I see two fixes (depending on what you want)

    This will put the button on the same sheet as r.
    Please Login or Register  to view this content.
    This will put the button on Sheet("Dashboard") one cell left of the same cell as r.
    Please Login or Register  to view this content.
    mikerickson,
    What do you mean by "unqualified range?"

    Yes, the button is being created on dSht (not nessesarily the same sheet as r):
    I am comparing data on from sheet (iSHT) with what is at the range "r", then the createButton is being called. Should I call createButton this way (Would this quality the range that is being sent as a parameter to createButton?:
    Please Login or Register  to view this content.


    The button still persists to be created in the wrong place... I'm checking the range immediately before button.add is being called and it's correct...

  7. #7
    Registered User
    Join Date
    09-28-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: button is being creating 2 rows above

    Jeff:

    Here is a "sanitized" version. This is where createButton() is being called:
    Please Login or Register  to view this content.
    Last edited by GunNam; 11-27-2010 at 08:21 PM. Reason: Grammatical errors

  8. #8
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,230

    Re: button is being creating 2 rows above

    By unqualified range, I was refering to the OP
    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)

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