+ Reply to Thread
Results 1 to 6 of 6

Excel Macro: If cell value in range is <>"", then clear offset cells

  1. #1
    Registered User
    Join Date
    06-26-2018
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    18

    Excel Macro: If cell value in range is <>"", then clear offset cells

    Hi everyone,

    Was hoping someone out there might be able to show me more efficient way of writing some simple VBA. Current the execution is time consuming, and the example file I have posted is only a fraction of the entire ranges I need to run the Macro on.

    The problem is this:

    I want to create a macro whereby, if the cells in column N have values in them (or not blank), the adjacent columns O -> S are cleared. Given I am running the code over multiple spreadsheets and thousands of rows, it is taking approximately 2 mins 30 sec to execute the code. Kinda defeats the purpose of automating the task when I could do it manually in less time.

    Very interested to hear your thoughts and suggestions

    Here is my current code:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Jackson2806; 12-31-2018 at 08:56 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2407 Win 11 Home 64 Bit
    Posts
    24,084

    Re: Excel Macro: If cell value in range is <>"", then clear offset cells

    Code Tags Added
    Your post does not comply with Rule 2 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.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,205

    Re: Excel Macro: If cell value in range is <>"", then clear offset cells

    If col N has values rather than formulae try
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Excel Macro: If cell value in range is <>"", then clear offset cells

    Can I suggest that rather than looping through cells which will take a long time you Autofilter the data so that just the cells/rows yuo're interested in are showing - use a helper column if necessary to identofy those rows.

    Then use the

    Range("your_range").SpecialCells(xlCellTypeVisible)

    syntax to identify the cells you want to clear and apply the blank. This requires just one VBA call back to the Excel App to do the job not the many rows that a loop involves
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    06-26-2018
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    18

    Re: Excel Macro: If cell value in range is <>"", then clear offset cells

    Hi Fluff13,

    I ran this code and it works a treat! Over a much larger project, this executed in a timely manner on multiple sheets.

    Thank you for getting back to me

    Regards

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,205

    Re: Excel Macro: If cell value in range is <>"", then clear offset cells

    Glad to help & thanks for the feedback

+ 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] Trying to add a macro to activate another macro to "click" a command button to clear cells
    By nthpl888 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-13-2016, 02:52 PM
  2. [SOLVED] Event to check cells in Range("I207:I216") contains number ealse clear contents
    By mangesh.mehendale in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-12-2015, 12:07 AM
  3. VBA if cell value(s) in range ="1/0/1900" clear contents
    By Tom_Watson123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-08-2015, 07:38 PM
  4. [SOLVED] A "No" response in Cell A1 populates a range of cells (A2:A10) as "N/A"
    By Dutch01 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-24-2015, 06:43 PM
  5. Clear content of range of cells if value is ""
    By ron2k_1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 12:59 PM
  6. Replies: 12
    Last Post: 10-15-2012, 03:57 PM
  7. [SOLVED] If Cell in column = "Y" then with offset (0, 1).value match to sheet range A3:A return ...
    By Spyderz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2012, 02:00 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