• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Code for Clear Contents in different sheets containing different rows and columns

Hi All,
For clearing contents I had written a vba code but I had written separately for all the sheets as because different sheet contains different rows & column.

Is there any way ( vba code ) where I can run all of them together and my contents gets cleared.

Please help.
ThanksRaj
 

Attachments

  • qrt.xlsm
    35.2 KB · Views: 17
Change code to this. When you run macro - you will only see "DELETE"


Code:
Private Sub DELETE1()
Worksheets("suven").Range("g2:G117").ClearContents
End Sub
Private Sub DELETE2()
Worksheets("suman").Range("f2:f197").ClearContents
End Sub
Private Sub DELETE3()
Worksheets("raj").Range("e2:e100").ClearContents
End Sub
Sub DELETE()

Call DELETE1
Call DELETE2
Call DELETE3

End Sub
 
Hi Chirayu

Thanks a lot.
Just one question I am having 60 sheets so for all the sheets I need to write the private sub functions and then call delete for all the sheets.
or is there any other way to do it.

Kindly suggest.


Thanks Raj
 
Delete all the code & use this instead

Code:
Sub ClearCols()

Dim LstRow As String
Dim ws As Worksheet
Dim EndCol As String

For Each ws In ActiveWorkbook.Worksheets
    ws.Select
    LstRow = Cells(Rows.Count, "A").End(xlUp).Row
    Range("A1").End(xlToRight).Offset(1, 0).Select
    EndCol = Split(ActiveCell.Address, "$")(1)
    Range(EndCol & "2:" & EndCol & LstRow).ClearContents
Next

End Sub
 
Instead of select, you can do it like this.
Code:
Sub DelLastCol()
Dim ws As Worksheet
Dim lRow As Long

For Each ws In ThisWorkbook.Worksheets
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
    ws.UsedRange.End(xlToRight).Resize(lRow, 1).Offset(1, 0).ClearContents
Next ws
End Sub
 
Hi !

Another way just respecting TBTO rule :​
Code:
Sub ClearLastColumn()
         Dim Ws As Worksheet
         Application.ScreenUpdating = False
    For Each Ws In ThisWorkbook.Worksheets
        With Ws.UsedRange.Columns
            .Item(.Count).Offset(1).ClearContents
        End With
    Next
         Application.ScreenUpdating = True
End Sub
rush2rajen, reminder :
Do you like it ? So thanks to click on bottom right Like !
This applies for any post that helped you …
 
Back
Top