Consulting

Results 1 to 4 of 4

Thread: Solved: Insert a formula if a different cell is not blank

  1. #1
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location

    Solved: Insert a formula if a different cell is not blank

    Can a Macro insert/write a Formula into a cell based on a different cell in the same row not being blank.

    In example, if Cell D2 has anything then Cell H2 needs to have =Concatenate(B2,A2,C2).

    The macro would have review each row and write the same formula in Column H but adjusted to match the particular row number.

    Thanks...

    Jim

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps something like this
    [VBA]Sub test()
    With ThisWorkbook.Sheets("sheet1")
    On Error Resume Next
    With Application.Intersect(.Range("H:H"), .Range("D").SpecialCells(xlCellTypeConstants).EntireRow)
    .FormulaR1C1 = "=CONCATENATE(RC2,RC1,RC3)"
    End With
    With Application.Intersect(.Range("H:H"), .Range("D").SpecialCells(xlCellTypeFormulas).EntireRow)
    .FormulaR1C1 = "=CONCATENATE(RC2,RC1,RC3)"
    End With
    On Error GoTo 0
    End With
    End Sub[/VBA]

  3. #3
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location
    Thanks, is there a way that the concatenate can do (add / between the 3 entries)?

    =concatenate(RC2," / ", RC1," / ",RC3)

    Jim

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    That looks like it might work if the " are doubled inside the string.

Posting Permissions

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