Consulting

Results 1 to 4 of 4

Thread: VBA CODE for Subtract two cells

  1. #1
    VBAX Contributor
    Joined
    Jun 2019
    Posts
    155
    Location

    VBA CODE for Subtract two cells

    Hi,

    I have data in the range of A30 to B187. I want to subtract B-A and update in C( Example: C30=B30-A30) . If A30 & B30 is blank the C30 also blank.

    How to write code for this

  2. #2
    Try this macro
    Sub my_code()
        With Range("C30:C187")
            .Formula = _
            "=IF(AND(A30="""",B30=""""),"""",B30-A30)"
            .Value = .Value
        End With
    End Sub

  3. #3
    VBAX Contributor
    Joined
    Jun 2019
    Posts
    155
    Location
    Dear Salim Ali

    Thanks for your reply. The code is working good.

  4. #4
    VBAX Contributor
    Joined
    Jun 2019
    Posts
    155
    Location
    Dear Salim,

    I have data updating in range "H30 to H186". If any value is going more than 2 in C column cell color to be change in yellow.

    For example H40 value is >= +or- 2 then C40 cell color to be change in yellow and popup message to be display that " C40 value is crossed 2"

    How can i do this code

Posting Permissions

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