Delete Row Using Filters with a Macro

jrhguez

New Member
Joined
May 8, 2008
Messages
48
Hello: I created a macro to reformat the following spreadsheet. Column N (Resulting Current Projection) is a formula of: L + M. The formula only needs to be added to any row with code "R" from column B. The problem I am having is that even though I filter code R, the formula carries down to other rows down the bottom of the spreadsheet when I run other reports. Some reports may have 100 rows an others may have 70..All reports begin in row 6


Row #ABCDEFGHIJKLMN
JobCode#AcctCategory CodeCategoryOriginal BudgetJV Change OrderRevised BudgetCommitedOther CostsCurrent ProjectionRequested ChangesResulting Current Projection
6 H2147322575-00-0000LAND
7 R6147322675-50-0050Land3,550,000.000.003,550,000.000.003,400,000.003,400,000.00 3,400,000.00
8 R6147323075-50-0150Escrow Deposits250,000.000.00250,000.000.00399,782.00399,782.00 399,782.00
9 T2147324075-99-9990TOTAL LAND3,800,000.000.003,800,000.000.003,799,782.003,799,782.00
10 H2147324176-00-0000TAXES & LICENSES
11 R6147324276-51-0050Property Taxes (realty)300,000.000.00300,000.000.00125,891.72125,891.72 125,891.72
12 R6147324676-51-0250Tax Consultant0.000.000.000.00150.00150.00 150.00
13 T2147325076-99-9990TOTAL TAXES & LICENSES300,000.000.00300,000.000.00126,041.72126,041.72
14 H2147325177-00-0000LEGAL
15 R6147325377-52-0100Construction Lender - Legal75,000.000.0075,000.000.00630.00630.00 630.00
16 R6147325677-52-0300Legal - Other0.000.000.000.00108,751.16108,751.16 108,751.16
17 R6147325877-52-0700Land Use Legal/Zoning50,000.000.0050,000.000.005,770.845,770.84 5,770.84
18 R6147325977-52-0720Land-Legal150,000.000.00150,000.000.00156,233.58156,233.58 156,233.58
19 R6147326077-52-0725Loan-Legal75,000.0025,000.00100,000.000.00111,439.81111,439.81 111,439.81
20 R6147326177-52-0730Entity Formation-Legal0.000.000.000.002,907.302,907.30 2,907.30
21 T2147326277-99-9990TOTAL LEGAL350,000.0025,000.00375,000.000.00385,732.69385,732.69
22 H2147326378-00-0000CLOSING COSTS
23 R6147326478-53-0050Title Insurance30,000.0033,363.0063,363.000.00105,192.12105,192.12 105,192.12
24 R6147326678-53-0100Recording Costs0.000.000.000.007,762.007,762.00 7,762.00
25 R6147326878-53-0150Documentary Stamps20,000.000.0020,000.000.000.000.00 0.00
26 R6147327178-53-0350Closing Costs - other200,000.000.00200,000.000.007.507.50 7.50
27 T2147327678-99-9990TOTAL CLOSING COSTS250,000.0033,363.00283,363.000.00112,961.62112,961.62
28 H2147327779-00-0000FINANCING
29 R6147327879-54-0150Construction Loan Fees246,000.0015,000.00261,000.000.00244,470.00244,470.00 244,470.00
30 R6147327979-54-0250Equity Placement Fee400,000.000.00400,000.000.00340,000.00340,000.00 340,000.00
31 R6147328379-54-0500Financing Fee - Other207,433.000.00207,433.000.0023.0023.00 23.00
32 R6147328579-54-0600Appraisal100,000.0010,000.00110,000.000.009,474.009,474.00 9,474.00
33 T2147328679-99-9990TOTAL FINANCING953,433.0025,000.00978,433.000.00593,967.00593,967.00
34 H2147328780-00-0000MUNI FEES
35 R6147328880-55-0050Planning Fees10,000.000.0010,000.000.000.000.00 0.00
36 R6147328980-55-0100Building Fees282,000.000.00282,000.000.00294,809.00294,809.00 294,809.00
37 R6147329180-55-0200Park Fees17,000.000.0017,000.000.000.000.00 0.00
38 R6147329380-55-0300Traffic Fees60,000.000.0060,000.000.000.000.00 0.00
39 R6147329580-55-0400Engineering Fees26,050.000.0026,050.000.000.000.00 0.00
40 R6147329680-55-0460Drainage Impact Fees132,000.000.00132,000.000.00121,182.00121,182.00 121,182.00
41 R6147329780-55-0480Utility Fees0.000.000.000.00(92.00)(92.00) (92.00)
42 R6147329980-55-0550Other Muni Fees585,075.000.00585,075.000.00648,711.00648,711.00 648,711.00
43 R6147330080-55-0600Waterline SDC24,000.000.0024,000.000.000.000.00 0.00
44 R6147330280-55-0800Performance Bonds0.000.000.000.002,644.002,644.00 2,644.00
45 R6147330380-55-1450Permit Processing20,000.000.0020,000.000.0019,563.0019,563.00 19,563.00
T2147331180-99-9990TOTAL MUNI FEES1,156,125.000.001,156,125.000.001,086,817.001,086,817.00

<colgroup><col><col><col span="3"><col><col><col span="8"></colgroup><tbody>
</tbody>

Thank you

Jonathan

<colgroup><col><col><col span="3"><col><col><col span="8"></colgroup><tbody>
</tbody>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Perhaps this will help..The same question applies when i filter the accounts highlighted in red below. These accounts need to be deleted, however they can be in different row #s within the report

Code:
Sub Macro_Worksheet()
'
' Macro_Worksheet Macro
'


'
    Windows("wip_projcost_pcmain_1228(1).xlsx").Activate
    Range("A4:T4").Select
    Selection.AutoFilter
    Columns("M:M").Select
    Selection.Delete Shift:=xlToLeft
    Columns("O:O").Select
    Selection.Delete Shift:=xlToLeft
    Columns("G:Q").Select
    Selection.ColumnWidth = 15
    Columns("R:R").Select
    Selection.ColumnWidth = 15
    Columns("M:N").Select
    Selection.Insert Shift:=xlToRight
    Range("M1").Select
    ActiveCell.FormulaR1C1 = "DATA THIS"
    Range("M2").Select
    ActiveCell.FormulaR1C1 = "COLUMN"
    Range("M1:M2").Select
    Range("M2").Activate
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True
    Range("M4").Select
    ActiveCell.FormulaR1C1 = "Requested Changes"
    Range("N4").Select
    ActiveCell.FormulaR1C1 = "Resulting Current Projection"
    Range("G5").Select
    ActiveWindow.SmallScroll Down:=-3
    Range("F5:S381").Select
    Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
    Columns("A:E").Select
    Selection.EntireColumn.Hidden = False
    Range("D11").Select
        [COLOR=#ff0000]ActiveSheet.Range("$A$4:$T$120").AutoFilter Field:=4, Criteria1:=Array( _
        "1472475", "1472476", "1473539", "1473542"), Operator:=xlFilterValues[/COLOR]
    Rows("5:227").Select
    Range("B5").Activate
    Selection.Delete Shift:=xlUp
    ActiveSheet.Range("$A$4:$T$162").AutoFilter Field:=4
    Range("B9").Select
    ActiveSheet.Range("$A$4:$T$162").AutoFilter Field:=1, Criteria1:="<>"
    Rows("162:162").Select
    Selection.Delete Shift:=xlUp
    ActiveSheet.Range("$A$4:$T$161").AutoFilter Field:=1
    ActiveSheet.Range("$A$4:$T$161").AutoFilter Field:=2, Criteria1:="R"
    Range("N6").Select
    ActiveCell.FormulaR1C1 = "=+RC[-2]+RC[-1]"
    Range("N6").Select
    Selection.Copy
    Range("N7:N159").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("M6:N159").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
    Range("M10").Select
    ActiveSheet.Range("$A$4:$T$161").AutoFilter Field:=2
    Range("E10").Select
    ActiveWindow.SmallScroll Down:=-18
    Columns("B:D").Select
    Selection.EntireColumn.Hidden = True
    Range("G5").Select
    ActiveWindow.SmallScroll Down:=-6
    Range("H5").Select
    ActiveWindow.FreezePanes = True
    ActiveWindow.SmallScroll Down:=-18
    Range("A4").Select
    ActiveWindow.SmallScroll ToRight:=2
    Range("A4:T4").Select
    Selection.AutoFilter
    Sheets("Projected_Cost_Report").Select
    Sheets("Projected_Cost_Report").Name = "PCR Worksheet"
    Range("F7").Select
    Windows("PERSONAL.XLSB").Activate
End Sub
 
Last edited by a moderator:
Upvote 0
You could use
Code:
With ActiveSheet
   .Range("$A$4:$T$120").AutoFilter Field:=4, Criteria1:=Array( _
        "1472475", "1472476", "1473539", "1473542"), Operator:=xlFilterValues
   .AutoFilter.Range.Offset(1).EntireRow.Delete
End With
 
Upvote 0
Thank you...Any suggestions for my first question?

Hello: I created a macro to reformat the following spreadsheet. Column N (Resulting Current Projection) is a formula of: L + M. The formula only needs to be added to any row with code "R" from column B. The problem I am having is that even though I filter code R, the formula carries down to other rows down the bottom of the spreadsheet when I run other reports. Some reports may have 100 rows an others may have 70..All reports begin in row 6
 
Upvote 0
Replace this
Code:
ActiveSheet.Range("$A$4:$T$161").AutoFilter Field:=1
    ActiveSheet.Range("$A$4:$T$161").AutoFilter Field:=2, Criteria1:="R"
    Range("N6").Select
    ActiveCell.FormulaR1C1 = "=+RC[-2]+RC[-1]"
    Range("N6").Select
    Selection.Copy
    Range("N7:N159").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
with
Code:
   With ActiveSheet
      .Range("$A$4:$T$161").AutoFilter Field:=1
      .Range("$A$4:$T$161").AutoFilter Field:=2, Criteria1:="R"
      .AutoFilter.Range.Offset(1).Columns(14).FormulaR1C1 = "=RC[-2]+RC[-1]"
   End With
 
Upvote 0
So sorry, how could I apply the same so the tintandshade doesn't copy down like the formula was doing it

Range("M6:N159").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0

Thanks
 
Upvote 0
Good Morning: I was wondering if you got a chance to look to my last minute question from yesterday (#6)...Thank you again for all your assistance

Regards,
Jonathan
 
Upvote 0
How about
Code:
   With ActiveSheet
      .Range("$A$4:$T$161").AutoFilter Field:=1
      .Range("$A$4:$T$161").AutoFilter Field:=2, Criteria1:="R"
      .AutoFilter.Range.Offset(1).Columns(14).FormulaR1C1 = "=RC[-2]+RC[-1]"
      With .AutoFilter.Range.Offset(1).Columns("M:N").Interior
         .Pattern = xlSolid
         .PatternColorIndex = xlAutomatic
         .ThemeColor = xlThemeColorAccent5
         .TintAndShade = 0.599993896298105
         .PatternTintAndShade = 0
      End With
   End With
 
Upvote 0
Hi again: This worked, but now is not showing the column in blue like it was showing it before
 
Upvote 0
That's just setting the colour to what your code had, so I've no idea why it's different.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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