Macro to clear particular rows and columns in multiple worksheets

I am looking for a macro that clears fields in particular tabs in a workbook. I would like to clear from A2 to M2 all the way down (all data within this range). I want to set this to a command button so it clears these fields in the 'Import', 'Current', and 'Closed' tabs. There are formulas in columns N, O, and P within these tabs but that macro shouldn't clear these. Lastly, on the 'Table of Content' tab, where it is labeled "<Customer> Carelog", if it can replace whatever the customer may be back to say "<Customer> Carelog", that would complete this macro (necessary to restart report to new for user).
DSE-Carelog-Report.xlsm
AckeemKAsked:
Who is Participating?
 
Roy CoxGroup Finance ManagerCommented:
Try this

Option Explicit
Sub Cleardata()
    Dim sht As Worksheet

    For Each sht In ThisWorkbook.Worksheets
        Select Case sht.Name
        Case "Import", "Current", "Closed"
            With sht
                .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 13).ClearContents
            End With
        End Select
    Next sht
    Sheets("Table of Contents").Range("b3").Value = "<Customer> Carelog"
End Sub

Open in new window

0
 
Roy CoxGroup Finance ManagerCommented:
Why don't you use Excel Data tables then you won't need to need to have unused Formulas in the sheets. The coding would also be simpler.
There's no data in Columns L & M is this a mistake?

Option Explicit
Sub Cleardata()
    Dim sht As Worksheet

    For Each sht In ThisWorkbook.Worksheets
        Select Case sht.Name
        Case "Import", "Current", "Closed"
            With sht
                .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 13).ClearContents
            End With
        End Select
    Next sht
End Sub

Open in new window


Which cell in TOC do you want changing?
0
 
AckeemKAuthor Commented:
B3 is the cell on the TOC that I want to reset after clearing all the tabs.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AckeemKAuthor Commented:
I noticed that it is deleting my column headers as well. Is it because I want the panes to be frozen in both the 'Current' and 'Closed' tabs? The first row and column is what I am looking to do and I think the macro clears the headers due to the frozen panes.
0
 
Roy CoxGroup Finance ManagerCommented:
There's no Header Column in Import. The code does not affect the header Row when I run it even with FreezePanes set
0
 
AckeemKAuthor Commented:
For me, when I click on the "Restart Report" button on the table of contents tab, it clears the report and the column headers in the 'Closed' and 'Current' tab. Not sure if there's a way to fix that. Even when I unfreeze the panes and click restart report, it still clears the headers but leaves it green.
0
 
Roy CoxGroup Finance ManagerCommented:
Attach this workbook and I'll take a look at it.
0
 
AckeemKAuthor Commented:
Attached is the reporting tool along with a import file to test with. Some issues occured once I combined macros within the "Import Report File(s)" button but it will still import the file into the import tab.
DSE-Carelog-Report.xlsm
emc-ticket-history-view-2015-03-31-1432-
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.