0

I am trying to get an Excel If formula to apply to all rows with content in a sheet. If the cell value entered after the macro is applied is y, then something appears in the next column, if it is n something else appears. It looks like this:

For Row = 2 To LastRow
        Cells(Row, 8).Formula = "=IF(""H"" & Row & ""="" ""Y"",""Included"",IF(""H"" & Row & ""="" ""N"",""SYS"", """"))"
    Next

I believe the issue is with where I putting the quotes and how many, but I can't figure that out for the life of me. I was able to get the formula to work when I chose a specific cell, ie. H2, but the issue began when I tried to use a variable.

Any help or tips or references would be appreciated!

1 Answer 1

1

I find it easier to replace tokens than to use concatenation, as it's easier to manage the quotes that way.

Const FRM As String  = "=IF(H<r>=""Y"",""Included"",IF(H<r>=""N"",""SYS"", """"))"
For Row = 2 To LastRow
    Cells(Row, 8).Formula = Replace(FRM, "<r>", Row
Next
Sign up to request clarification or add additional context in comments.

1 Comment

GAMECHANGER. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.