Excel Task ideas

Jemma Atkinson

Well-known Member
Joined
Jul 7, 2008
Messages
509
Hi, i have a workbook which has 3 worksheets("Cash", "Securities", Physical Securities")

This workbook which contains outstanding reconcilliation breaks gets sent to the client each month.

In Sheet "Cash" Col U is Status, which is either blank or has the string "CLEARED" for each row of data

In Sheet "Securities" it will be Col S and sheet Physical Securities it will Col R.

Question i only want to show the client the data which is not CLEARED. What is the best approach in doing this?
 
I made some changes in the code. Try this:

Code:
Sub DataNotCleared()
    Dim mySheet As Worksheet
    Dim LastRow, LastCol As Long
    Dim i As Integer
 
    Application.ScreenUpdating = False
 
    For i = 1 To 3
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets("Data" & i).Delete
        Application.DisplayAlerts = True
        On Error GoTo 0
        Sheets.Add After:=Sheets(Sheets.Count)
        ActiveSheet.Name = "Data" & i
        Set mySheet = Sheets(Choose(i, "Cash", "Securities", "Physical Securities"))
        LastRow = mySheet.Cells(Rows.Count, 1).End(xlUp).Row
        LastCol = mySheet.Cells(11, Columns.Count).End(xlToLeft).Column
        Cells(1, LastCol + 2).Value = "Status"
        Cells(2, LastCol + 2).Formula = "=""<>CLEARED"""
        mySheet.Range(Cells(1, 1).Address, Cells(LastRow, LastCol).Address).AdvancedFilter _
            Action:=xlFilterCopy, _
            CriteriaRange:=Range(Cells(1, LastCol + 2), Cells(2, LastCol + 2)), _
            CopyToRange:=Cells(1, 1)
        Range(Cells(1, LastCol + 2), Cells(2, LastCol + 2)).Clear
    Next i
 
    Sheets(Array("Data1", "Data2", "Data3")).Move
    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\DATANOTCLEARED"
    ActiveWorkbook.Close
 
    Set mySheet = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Thanks for this.

I made some changes in the code. Try this:

Code:
Sub DataNotCleared()
    Dim mySheet As Worksheet
    Dim LastRow, LastCol As Long
    Dim i As Integer
 
    Application.ScreenUpdating = False
 
    For i = 1 To 3
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets("Data" & i).Delete
        Application.DisplayAlerts = True
        On Error GoTo 0
        Sheets.Add After:=Sheets(Sheets.Count)
        ActiveSheet.Name = "Data" & i
        Set mySheet = Sheets(Choose(i, "Cash", "Securities", "Physical Securities"))
        LastRow = mySheet.Cells(Rows.Count, 1).End(xlUp).Row
        LastCol = mySheet.Cells(11, Columns.Count).End(xlToLeft).Column
        Cells(1, LastCol + 2).Value = "Status"
        Cells(2, LastCol + 2).Formula = "=""<>CLEARED"""
        mySheet.Range(Cells(1, 1).Address, Cells(LastRow, LastCol).Address).AdvancedFilter _
            Action:=xlFilterCopy, _
            CriteriaRange:=Range(Cells(1, LastCol + 2), Cells(2, LastCol + 2)), _
            CopyToRange:=Cells(1, 1)
        Range(Cells(1, LastCol + 2), Cells(2, LastCol + 2)).Clear
    Next i
 
    Sheets(Array("Data1", "Data2", "Data3")).Move
    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\DATANOTCLEARED"
    ActiveWorkbook.Close
 
    Set mySheet = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Jemma,

I have to say: i would adopt Norie's approach - create a new worbook with only the relevant data to your clients.

Its a much better practice and safer than delete rows (or anything) of your original workbook.

M.

The orignal workbook stays intact, I have a code that saves the file as a different name and then deletes the rows.
 
Upvote 0
Code:
[COLOR="Blue"]Sub[/COLOR] NotCleared()

    [COLOR="Blue"]Dim[/COLOR] rng [COLOR="Blue"]As[/COLOR] Range
    [COLOR="Blue"]Dim[/COLOR] sh [COLOR="Blue"]As[/COLOR] Worksheet
    [COLOR="Blue"]Dim[/COLOR] arrSheets [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Variant[/COLOR], arrCols [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Variant[/COLOR]
    
    [COLOR="Blue"]Set[/COLOR] sh = Sheets.Add(After:=Sheets(Sheets.Count))
    [COLOR="Blue"]With[/COLOR] sh: .Name = "Consolidation": .Tab.ColorIndex = 6: [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    
    arrSheets = VBA.Array("Cash", "Securities", "Physical Securities")
    arrCols = VBA.Array("U", "S", "R")
    
    [COLOR="Blue"]For[/COLOR] i = 0 [COLOR="Blue"]To[/COLOR] 2
        [COLOR="Blue"]With[/COLOR] Sheets(arrSheets(i))
            lastRow = .Cells(Rows.Count, arrCols(i)).Row
            [COLOR="Blue"]If[/COLOR] .AutoFilterMode [COLOR="Blue"]Then[/COLOR] .AutoFilter.Range.AutoFilter
            .Cells(1, arrCols(i)).AutoFilter Field:=1, Criteria1:="<>CLEARED"
            [COLOR="Blue"]Set[/COLOR] rng = .Range(.Cells(2, "A", .Cells(lastRow, arrCols(i)))).SpecialCells(xlCellTypeVisible)
            [COLOR="Blue"]If[/COLOR] [COLOR="Blue"]Not[/COLOR] rng [COLOR="Blue"]Is[/COLOR] [COLOR="Blue"]Nothing[/COLOR] [COLOR="Blue"]Then[/COLOR]
                rng.Copy
                sh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            [COLOR="Blue"]Next[/COLOR]
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    [COLOR="Blue"]Next[/COLOR]

[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Last edited:
Upvote 0
Jemma


What code are you actually using?


There are quite a few posts with code that will delete/clear data from the original workbook.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top