Consulting

Results 1 to 3 of 3

Thread: insert formula via loop including cell contents in a range

  1. #1
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location

    insert formula via loop including cell contents in a range

    I am trying to write code that will take the current value of cells in range and add an excel if formula to analyze if the cell value in a few columns over is zero to display or not display information of the current cell value

    Here is my code
    '-----------
    Dim RNG As Range
    Dim Cell As Range

    Set RNG = Worksheets("report").Range("a8:c11")

    For Each Cell In RNG
    Cell.Formula = "=if($g8=0,""""," & """" & Cell.Value & """" & ")"

    ' comment - this is the equivalent of =if(g8=0,"",cell value) meaning if g8 s zero take the current cell value and show nothing or "" in my case

    'Next
    '-----------
    I need g8 to change to g9, g10, etc to the end of range (row only change) but it does not. It uses G8 in each formula for the range.

  2. #2
    Maybe somthing like this?


    Cell.Formula = "=if($G" & Cell.Row & "=0,""""," & """" & Cell.Value & """" & ")"
    Last edited by rlv; 11-15-2018 at 02:27 PM. Reason: typo

  3. #3
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location
    Dear rlv, thank you, this worked perfectly. I appreciate you providing this solution to me.

Posting Permissions

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