Results 1 to 3 of 3

VBA: Clearing Offset cells

Threaded View

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

    VBA: Clearing Offset cells

    Hi everyone,

    I had some help with a recent problem in clearing offset cells. The code suggested worked very well until I required a different column arrangement. Hoping someone could shed some light on a fix.

    Here is the problem (excel file included):

    I want to remove values from column D & E, under the condition that columns A & B have values in them. The current code removes required values from column D & E.

    I have tried including an if statement to say, "if the value in column A & B are <>"", then clear offset cells in columns C&D". This approach does not seem to work. When the code is run, offset cells are removed all the way down to the end of the month, which I am don't want.

    Hope someone can help

    Here is my code:

    Sub Clearcells()
    
    Dim rng As Range
    Dim Ar As Areas
    Set Ar = Range("B5", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
    
       For Each rng In Ar
        rng.Offset(, 2).Resize(, 1).ClearContents
       Next rng
       
    
    Dim rng2 As Range
    Dim Ar2 As Areas
    Set Ar2 = Range("C5", Range("C" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
    
       For Each rng2 In Ar2
          rng2.Offset(, 2).Resize(, 1).ClearContents
       Next rng2
    
    
    End Sub
    Attached Files Attached Files
    Last edited by Jackson2806; 01-01-2019 at 11:19 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Select offset variable offset cells
    By papasmurfuo9 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-02-2014, 06:12 AM
  2. Clearing option buttons based a on cells value where the cells value is not typed in.
    By Tanner2004 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2013, 03:56 PM
  3. Clearing Contents in 2 cells, based on the value of 3 cells
    By hriggs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2009, 06:39 AM
  4. Clearing cells using VBA
    By StuntMonkeh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-14-2008, 11:36 AM
  5. Clearing Cells
    By Andyd74 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2006, 12:35 PM
  6. [SOLVED] Clearing cells
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2006, 05:55 PM
  7. Clearing Cells
    By mully in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 05-19-2005, 04:06 PM

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