+ Reply to Thread
Results 1 to 5 of 5

Clear non-adjacent columns

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-16-2014
    Location
    Witbank, SA
    MS-Off Ver
    Excel 2013
    Posts
    268

    Clear non-adjacent columns

    Hi there,

    please, kindly assist me with a teeny problem. I need a code which will clear the contents of columns B to H, from cells 4, then skip one column and clear the next 7 columns..and carry on like this right to columns DHB to DHH. Thank you very much..

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Clear non-adjacent columns

    hHi, juriemagic,

    maybe this:
    Sub EF1050610()
    Dim lngCtr As Long
    For lngCtr = Range("B1").Column To Range("DBH1").Column Step 8
      Range(Cells(4, lngCtr), Cells(Rows.Count, lngCtr + 6).End(xlUp)).ClearContents
    Next lngCtr
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    04-16-2014
    Location
    Witbank, SA
    MS-Off Ver
    Excel 2013
    Posts
    268

    Re: Clear non-adjacent columns

    Absolutely brilliant!..Once again I thank you Holger..

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Clear non-adjacent columns

    Hi, juriemagic,

    due to another thread here maybe alter the code to read
    Sub EF1050610_2()
    Dim lngCtr As Long
    For lngCtr = Range("B1").Column To Range("DBH1").Column Step 8
      Range(Cells(4, lngCtr), Cells(Rows.Count, lngCtr + 6)).ClearContents
    Next lngCtr
    End Sub
    just in case any of the last columns doesn´t hold additional values from row 4 on.

    Ciao,
    Holger

  5. #5
    Forum Contributor
    Join Date
    04-16-2014
    Location
    Witbank, SA
    MS-Off Ver
    Excel 2013
    Posts
    268

    Re: Clear non-adjacent columns

    Thanx Holger,

    Will keep this one in mind... have a good day..

+ 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. Clear multiple adjacent cells with Offset
    By sadyr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2014, 10:23 PM
  2. Clear cells upon adjacent cell change
    By jwstimac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-12-2013, 01:02 PM
  3. [SOLVED] can someone help modify the clear command to only clear columns from A-G?
    By psunursingguy21 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2013, 03:52 PM
  4. [SOLVED] VBA Code - Compare Adjacent Cells In two columns and clear contents when a match is found
    By Langer101 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-03-2013, 06:22 AM
  5. Macro to find bold cells then clear adjacent cell
    By painterartist in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-26-2011, 04:47 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