• 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.

SOLVED: How to clear contents of a table from Xth column

inddon

Member
Hello There,

I have an excel table ("Table1") with 10 columns. I would like to clear the contents from the 4th column till the last column.

I have the following code:

Code:
Private Sub BClearTable_Click()
Dim tbl1 As ListObject, tbl1RowCount As Integer, tbl1ColCount  As Integer

Set tbl1 = ActiveSheet.ListObjects("Table1")
tbl1RowCount = tbl3.DataBodyRange.Rows.Count
tbl1ColCount = tbl3.DataBodyRange.Columns.Count

'Delete all table rows except first row
  With tbl1.DataBodyRange
  If .Rows.Count > 1 Then
  .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Rows.Delete
  End If
  End With

'-----------------------------------------------------------------
'Column1,2 and 3 have formulas. Would like to clear the contents from the 
4th column onwards
'-----------------------------------------------------------------

How can this be done using VBA?


Thanks & regards,
Don
 
Last edited:
Hi Don ,

Try this :

Activesheet.Listobjects("Table1").DatabodyRange.Columns(4).Resize(,7).ClearContents

This will clear the contents of Table1 from column 4 through column 10.

Narayan


Thanks Narayank,

It works good.

Regards,
Don


PS. Could you please edit the subject and mark it as solved?
 
Back
Top