+ Reply to Thread
Results 1 to 2 of 2

Applying formula without effecting header

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Exclamation Applying formula without effecting header

    Hey guys,
    At the moment Im working on the below piece of code. I need this code to apply the formula to column 'N' and then paste special the values over themselves. Unfortunately this is a large marco and previously in the code the the header had been formatted and the sheet is broken up into various groups by blank grey lines.

    Would anybody have an idea as to how to apply this formula to all the populated cells in column'N' (excluding the header)??

    Range("N4").Select
        ActiveCell.FormulaR1C1 = "=IF(RC[-3]=""Yes"", ""Yes"","""")"
        Range("N4").Select
        Selection.Copy
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Range("N4").Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Applying formula without effecting header

    Hello TonyforVBA,

    how is the header identified? Does it have a specific word in a specific column, for example?

    If so, something like this might work better:

    Sub test()
    Dim cel As Range
    Dim HeaderID As String
    HeaderID = "Header"
    For Each cel In Range("N4:N" & Cells(Rows.Count, "A").End(xlUp).Row)
        If Not Range("A" & cel.Row).Text = HeaderID Then _
            cel.FormulaR1C1 = "=IF(RC[-3]=""Yes"", ""Yes"","""")"
    Next
    End Sub
    The macro checks if the word "Header" is in column A. If not, the formula gets inserted in the row in column N.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1