Macro to delete unwanted data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I would like to macro to delete all data from Row 3 onwards except the rows where the text "Current Closing Balance" appears in Col C as well as 2 rows above this

For Eg if CURRENT CLOSING BALANCE is in row 47, then Rows 45-47 must remain intact

Your assistance will be most appreciated
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,

Try:

Code:
Sub test()
    lRow = Range("C" & Rows.Count).End(xlUp).Row
    For i = lRow To 3 Step -1
        If Cells(i, 3).Value = "Current Closing Balance" Then
            i = i - 2
        Else
            Cells(i, 3).EntireRow.Delete
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Hi James

Thanks for the help.

The macro is curently clearing all the data

I need all rows from row 11 containing "CURRENT CLOSING BALANCE" (Col C) + 2 rows above it to remain intact (i.e the first 10 rows to be ignored)

I also need the rows to be deleted where the text appears "Acc Depr" in col C for eg Acc Depr Corporate signage. The the text will allways start with Acc Depr

Your assistance is most appreciated


Fixed Assets.xls
ABCDEFG
1
2Company:12Date:09/05/2011
3
4CurrentAccountingMonth:201105GENERALLEDGERTRANSACTIONLISTINGFORPERIOD:MONTH201103-201104Page:1
5
6------------------------------------------------------------------------------------------------------------------------------------
7ACCNO---------DESCRIPTION-------TPSrcAuditPosted
8DateRef.No.ControlCd
9----------------------------------------------------------------------------------------------------------------------------------
10----------------------------------------------------------------------------------------------------------------------------------
11101210CORPSIGNAGEATCOSTTOTALTRANSACTIONSFORTHEPERIOD00
12----------------------------------------------------------------------------------------------------------------------------------
13CURRENTCLOSINGBALANCE693818.53
14----------------------------------------------------------------------------------------------------------------------------------
15101211ACCDEPRCORPSIGNLOpeningBalanceforAcc.Month201103
16
1711/04/116928769287JGJ
18
19TotalAfterAccountingMonth201103
20----------------------------------------------------------------------------------------------------------------------------------
21----------------------------------------------------------------------------------------------------------------------------------
22101211ACCDEPRCORPSIGNTOTALTRANSACTIONSFORTHEPERIOD0-11189.4
23----------------------------------------------------------------------------------------------------------------------------------
24CURRENTCLOSINGBALANCE-593985
25----------------------------------------------------------------------------------------------------------------------------------
Sheet1



The data looks liks this after running the macro

Fixed Assets.xls
ABCDEFG
1
2Company:12Date:09/05/2011
3
4CurrentAccountingMonth:201105GENERALLEDGERTRANSACTIONLISTINGFORPERIOD:MONTH201103-201104Page:1
5
6------------------------------------------------------------------------------------------------------------------------------------
7------------------------------------------------------------------------------------------------------------------------------------
8
9-----------------------------------------------------------------------------------------------------------------------------------
10GENERALLEDGERTRANSACTIONLISTINGPage:1
Sheet1



The file must look more or less less this once the macro has run

Fixed Assets.xls
ABCDEF
1RunBy:HOWARDTime:12:21:02
2GLP520Company:10NissanEasternCapeDate:09/05/2011
3
4CurrentAccountingMonth:201105GENERALLEDGERTRANSACTIONLISTINGFORPERIOD:MONTH201103-201104Page:1
5
6------------------------------------------------------------------------------------------------------------------------------------
7ACCNO---------DESCRIPTION-------TPSrcAudit
8DateRef.No.Control
9----------------------------------------------------------------------------------------------------------------------------------
10----------------------------------------------------------------------------------------------------------------------------------
11101210CORPSIGNAGEATCOSTTOTALTRANSACTIONSFORTHEPERIOD00
12----------------------------------------------------------------------------------------------------------------------------------
13CURRENTCLOSINGBALANCE693818.53
14----------------------------------------------------------------------------------------------------------------------------------
15101211ACCDEPRCORPSIGNTOTALTRANSACTIONSFORTHEPERIOD0-11189.38
16----------------------------------------------------------------------------------------------------------------------------------
17CURRENTCLOSINGBALANCE-593984.64
18101212COMPEQUIPATCOSTTOTALTRANSACTIONSFORTHEPERIOD00
19----------------------------------------------------------------------------------------------------------------------------------
20CURRENTCLOSINGBALANCE0
21----------------------------------------------------------------------------------------------------------------------------------
22----------------------------------------------------------------------------------------------------------------------------------
23101213ACCDEPRCOMPEQUIPTOTALTRANSACTIONSFORTHEPERIOD00
24----------------------------------------------------------------------------------------------------------------------------------
25CURRENTCLOSINGBALANCE0
26----------------------------------------------------------------------------------------------------------------------------------
27101214PLANT&MACHATCOSTTOTALTRANSACTIONSFORTHEPERIOD0.01-46930.01
28----------------------------------------------------------------------------------------------------------------------------------
29CURRENTCLOSINGBALANCE464880.9
30
31
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

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