+ Reply to Thread
Results 1 to 11 of 11

Contentens Clearing on wrong worksheet

  1. #1
    Registered User
    Join Date
    05-07-2012
    Location
    Michigan
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    44

    Question Contentens Clearing on wrong worksheet

    Experts, I could really use some help and direction...

    I have a Marco that clears specific column of data on a worksheet [POF1_Load Format] before rewriting new data from Inputbox. It works correctly (As long As) I am on the correct worksheet however after I added an instructions Tab, the macro also clears part of my instruction as well as properly clears the data on the correct tab.

    I am trying to figure out how to do one of the two options below....

    1. click the button I created and have it switch to the input [POF1_Load Format] tab and execute the Marco so it will run correctly then go back to the instructions page

    2. when the button is clicked only clear the content defined in the [POF1_Load Format] tab.

    Below is my code and I have attached an Excel file with the code I have assembled, the excel file has been limited to only the data and information needed...

    Thank you in advance...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Jon_P; 01-31-2018 at 10:55 AM.

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Contentens Clearing on wrong worksheet

    Deleted because OP complied to Forum Rules.
    Last edited by bakerman2; 01-31-2018 at 11:52 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Contentens Clearing on wrong worksheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    That said, the purpose of using With is to avoid using Select.

    You need to use, for example, .Range("D2"), to link a range to the worksheet in the With statement



    Your code:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    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: Contentens Clearing on wrong worksheet

    Quote Originally Posted by TMS View Post
    That said, the purpose of using With is to avoid using Select.
    I don't think I would agree with that- the two aren't related?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Contentens Clearing on wrong worksheet

    Choice of words might not be ideal. However, as a general rule, you should avoid using Select. Using With allows you to create relationships and link objects. I believe it has efficiency advantages and can certainly shorten code statements. I use it to avoid using Select. Perhaps you don't or use it some other way.

    Whatever, I am fairly certain that using With in the code shown without linking the range to the worksheet is the cause of the issue. And I have never seen Select used within a With construct.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,366

    Re: Contentens Clearing on wrong worksheet

    Try:

    Please Login or Register  to view this content.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Contentens Clearing on wrong worksheet

    I'd go for this one because occasionally empty rows might be responsable for not clearing entire column D using End(xlDown)
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-07-2012
    Location
    Michigan
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    44

    Re: Contentens Clearing on wrong worksheet

    Thank for the quick replays, I will try both and let you know how they work...

  9. #9
    Registered User
    Join Date
    05-07-2012
    Location
    Michigan
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    44

    Re: Contentens Clearing on wrong worksheet

    bakerman2 worked perfectly... thank you..

  10. #10
    Registered User
    Join Date
    05-07-2012
    Location
    Michigan
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    44

    Re: Contentens Clearing on wrong worksheet

    I fixed it... Sorry, I will make sure to follow rule 3 next time...

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Contentens Clearing on wrong worksheet

    Glad to help.

+ 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. macro clearing wrong worksheet
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2017, 10:09 AM
  2. [SOLVED] Help? What am I doing wrong with clearing filters?
    By globulous in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-02-2015, 02:34 AM
  3. Help clearing linking and macro from worksheet
    By DanishDudeAU in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2014, 05:11 AM
  4. Clearing a Worksheet
    By CrazyFileMaker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2009, 08:05 PM
  5. [SOLVED] VBA for Clearing data from the worksheet
    By DORI in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-01-2005, 03:15 AM
  6. [SOLVED] my macro is clearing the wrong sheet
    By Polarbear in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2005, 04:05 PM
  7. [SOLVED] Worksheet clearing Macros?
    By Arlen in forum Excel General
    Replies: 4
    Last Post: 01-27-2005, 01:06 PM

Tags for this Thread

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