Macro to insert formula based on filter and visible cells

Kinez101

New Member
Joined
Oct 18, 2016
Messages
23
I am trying to create a macro to change value of the visible cells in column Y from zCSS to zContractAdmin based on the value of column K. This is the macro I have tried to use but it's giving me error on Formula. Any help is greatly appreciated.

Code:
Sub Macro2()


    Application.CutCopyMode = False
    Selection.AutoFilter
    ActiveWindow.LargeScroll ToRight:=1
    ActiveSheet.Range("$A$1:$BR$32000").AutoFilter Field:=25, Criteria1:="zCSS"
    Columns("Y:Y").Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.SpecialCells(xlCellTypeFormula).Formula="=IF((OR(K:K="C075",K:K="C099",K:K="C170",K:K="C228",K:K="D000",K:K="D060",K:K="D113")),"zContract Admin","zCSS")"
    
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try:
Code:
Sub ReplaceVal()
    Application.CutCopyMode = False
    Dim rng As Range
    ActiveSheet.Range("$Y$1:$Y$3200").AutoFilter Field:=1, Criteria1:="zCSS"
    For Each rng In Range("$K$2:$K$3200").SpecialCells(xlCellTypeVisible)
        Select Case rng.Value
            Case "C075", "C099", "C170", "C228", "D000", "D060", "D113"
                Range("Y" & rng.Row) = "zContract Admin"
        End Select
    Next rng
    If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
    Application.CutCopyMode = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,366
Messages
6,130,194
Members
449,565
Latest member
excelqueenintraining

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