+ Reply to Thread
Results 1 to 8 of 8

vba clear contents and any format in specific columns

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,143

    vba clear contents and any format in specific columns

    sheet observation , columns D and E ,H , V find last cells used then clear any format and contents of the last cell IN VBA

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: vba clear contents and any format in specific columns

    Dim cols as Variant
    Dim i as Long
    Dim r as String
    
    cols = Array("D", "E", "H", "V")
    
    For c = LBound(cols) to UBound(cols)
    
    Worksheets("observations").Range(c & Rows.Count).End(xlUp).Clear
    
    Next c
    Last edited by buran; 06-29-2017 at 07:06 AM.
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: vba clear contents and any format in specific columns

    Perhaps...Using buran's code....
    Option Explicit
    Sub JEAN1972()
    Dim cols As Variant
    Dim c As Long, lrow As Long
    cols = Array("D", "E", "H", "V")
    With Sheets("observations")
        For c = LBound(cols) To UBound(cols)
            lrow = .Cells(Rows.Count, cols(c)).End(xlUp).Row
            .Range(cols(c) & lrow).ClearContents
        Next c
    End With
    End Sub
    Edited...Or
    Option Explicit
    Sub JEAN1972()
    Dim cols As Variant
    Dim c As Long
    cols = Array("D", "E", "H", "V")
    With Sheets("observations")
        For c = LBound(cols) To UBound(cols)
           .Range(cols(c) & Rows.Count).End(xlUp).ClearContents
        Next c
    End With
    End Sub
    Last edited by Sintek; 06-28-2017 at 12:47 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,143

    Re: vba clear contents and any format in specific columns

    Buran & Sintek

    Thank you , an insight how to remove the cell borders linestyle from the last cell with the above code

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: vba clear contents and any format in specific columns

    Pleasure glad I could help...thanks for rep...


    an insight how to remove the cell borders linestyle from the last cell with the above code
    Option Explicit
    Sub JEAN1972()
    Dim cols As Variant
    Dim c As Long
    cols = Array("D", "E", "H", "V")
    With Sheets("observations")
        For c = LBound(cols) To UBound(cols)
            With .Range(cols(c) & Rows.Count).End(xlUp)
                .ClearContents
                .Borders.LineStyle = xlLineStyleNone
            End With
        Next c
    End With
    End Sub

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: vba clear contents and any format in specific columns

    of course, there should be no brackets:
    Worksheets("observations").Range(c & Rows.Count).End(xlUp).Clear
    sorry for he mistake and thanks for rep

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: vba clear contents and any format in specific columns

    @ buran
    Perhaps
    .Range(cols(c) & Rows.Count).End(xlUp).ClearContents
    Dim i as Long ' c as long

  8. #8
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: vba clear contents and any format in specific columns

    Yes, right. I have to stop for a moment and go for a coffee break :-)
    Last edited by buran; 06-29-2017 at 07:39 AM.

+ 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. VBA MAcro to clear contents of specific cells if a specific cell contains text
    By muzzareilly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2017, 12:47 PM
  2. Clear Contents specific range of many tables
    By salmasaied in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-05-2016, 04:01 PM
  3. [SOLVED] code to clear all contents in columns with specific text in row 2
    By xcelnovice101 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-30-2014, 08:58 AM
  4. [SOLVED] Clear contents in specific cell and the cells in the next 2 columns to the right
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2014, 01:25 AM
  5. [SOLVED] Clear contents of specific cells on the same row if a specific cell on that row is empty
    By djfscouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2014, 01:48 PM
  6. Clear Contents in Specific Rows via condition
    By Excel Newbie05 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-09-2008, 04:02 PM
  7. Replies: 1
    Last Post: 08-22-2006, 12:30 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