+ Reply to Thread
Results 1 to 9 of 9

How can I clear Active Row using VBA?

  1. #1
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    How can I clear Active Row using VBA?

    Hi everyone,

    I have a macro that clears the contents of the selected range in a worksheet, then it shifts the bottom cells up. I am wondering if there is a way to avoid selecting the range and clearing the ActiveRow up to Column M. Here is my macro:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jdcortez; 02-02-2019 at 06:22 PM.

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: How can I clear Active Row using VBA?

    This code will delete the contents of the col A thru M on the row of the activeCell (which is also the active row)
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How can I clear Active Row using VBA?

    Quote Originally Posted by Roel Jongman View Post
    This code will delete the contents of the col A thru M on the row of the activeCell (which is also the active row)
    Please Login or Register  to view this content.


    Unfortunately I cannot use delete as it will cause an error on my referenced cells. Is there any way to make your solution work with "Clear Contents"

  4. #4
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: How can I clear Active Row using VBA?

    Ah, ok,

    see if this code works then.. still only work on the activecell / active row but always A:M is cleared
    and all remaining rows are moved up 1 row

    Please Login or Register  to view this content.
    __________________
    forumguideline:
    2. Please don't quote whole posts -- it's just clutter.*

  5. #5
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How can I clear Active Row using VBA?

    Spoke too soon, its actually is causing an error on the referenced cell Side question, what if i wanted to ClearContents from C:M, which values would i change?
    Last edited by jdcortez; 02-02-2019 at 05:46 PM.

  6. #6
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: How can I clear Active Row using VBA?

    there is a few changes needed so here is changed code with highlighted changes

    Please Login or Register  to view this content.
    the 1's changed to 3 to reflect col C instead of A
    the resize only needs to expand 11 col from C to m instead of 13 from A to M.

    tip: if you press F1 in VBA editor while on a command f.e. Cells or Resize it will take you to the help and explain what it does. and what references rows and columns

    it might de down to me using the Cut and paste function that affects your references
    but because your example does only have constant values and no references pointing to other cells I cannot test if changing to copy paste code will work better.

  7. #7
    Registered User
    Join Date
    09-06-2017
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    33

    Re: How can I clear Active Row using VBA?

    i uploaded another workbook that references cell $A$2

  8. #8
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: How can I clear Active Row using VBA?

    Ok so the reference is outside of the data area that is being cleared and moved.
    IF you keep the values in column A and B does that then not affect the outcome? I mean col C: M will move 1 row up but A and B are still the same, also there will be values in A and B column at the bottom without any values in C:M. that amount of rows like that will grow depending on how often you delete the current row.

    So based on the new file. I would stick to copying A:M and use copy/paste
    that way you are sure all data of each line stays as it was before the delete of the active row.

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor mohan.r1980's Avatar
    Join Date
    09-18-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010 (windows7)
    Posts
    729

    Re: How can I clear Active Row using VBA?

    try
    Please Login or Register  to view this content.
    Regards,
    MohanS


    "Perfection is not attainable, but if we chase perfection we can catch excellence." - Vince Lombardi

    You can simply say thanks by clicking "*Add Reputation" icon

+ 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. A vba code to clear Active X Control Text Boxes
    By newqueen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-09-2023, 05:02 PM
  2. Find active row and clear content in that row
    By a94andwi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2018, 10:26 AM
  3. Macro to clear unlocked cells on active sheet
    By adamheon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2018, 09:59 AM
  4. [SOLVED] vba to clear contents in specific ranges on active sheet
    By blackburnsexcel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-01-2014, 09:35 AM
  5. Replies: 2
    Last Post: 06-21-2011, 12:54 AM
  6. clear filter for active coulmn
    By mdsahir in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2008, 07:15 AM
  7. How to set the position of a active cell and clear the contents of the cells
    By aijihz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2007, 04:46 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