Seeking to insert formula via code, when cell <> "unused"

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
734
Office Version
  1. 365
Platform
  1. Windows
Using XL2007: With a macro, I would like to carry down the formulas in Cells B3 and C3 only when the value in column A is not 'Unused'. If it helps, when a cell in column A = 'Unused', the sum of columns D:G in that row will also always be zero.

I've searched and also modified several codes, but this has me stumped.

Would appreciate any assistance.

thanks

jim

Excel Workbook
ABCDEFG
2SumAverageT1T2T3T4
3name11.7390.43475 0.615 0.096 0.970 0.058
4name2 0.866 0.379 0.580 0.974
5name3 0.384 0.543 0.141 0.974
6Unused - - - -
7Unused - - - -
8name4 1.771 0.775 1.186 1.992
9Unused - - - -
Calculations
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try:

Code:
Sub Test()
    With Range("A2").CurrentRegion
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="<>Unused", Operator:=xlAnd
        With .Offset(1).Resize(.Rows.Count - 1)
            .Columns(2).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=SUM(RC[2]:RC[5])"
            .Columns(3).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=AVERAGE(RC[1]:RC[4])"
        End With
        .AutoFilter
    End With
End Sub

The code assumes that row 1 is empty.
 
Upvote 0
Works well on a small sample - now on to the big test.

thanks

jim
 
Upvote 0
Row 1 in the larger project is populated, so this is close to what I need. The headings in my filter area start in row 5, formulas in row 6. Column C is filter field 1. My formulas need to populate in several columns to the right, starting in column D. I have the R1C1 formulas figured out. All I need is a way to set the filter range to start in in C5.

Thanks

jim
 
Upvote 0
Maybe try:

Code:
Sub Test()
    Dim LR As Long
    LR = Range("C" & Rows.Count).End(xlUp).Row
    With Range("C5:I" & LR)
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="<>Unused", Operator:=xlAnd
        With .Offset(1).Resize(.Rows.Count - 1)
            .Columns(2).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=SUM(RC[2]:RC[5])"
            .Columns(3).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=AVERAGE(RC[1]:RC[4])"
        End With
        .AutoFilter
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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