Request for assistance in VBA Coding RRS feed

  • Question

  • Hi,

    I have a excel spreadsheet where I need to replace all cell values by (1- cell value).  The range is C4 to ED144. I have not used VBA before, therefore I am requesting VBA codes for this problem.

    Kind Regards

    Sazzad Hossain

    • Edited by Sazzad H Monday, December 23, 2019 2:45 PM
    Monday, December 23, 2019 2:44 PM

All replies

  • If you need a simple solution, then check this macro:

    Sub ReplaceValues()
        Dim r As Range
        Set r = Range("C4", "ED144")
        Dim i As Integer
        Dim j As Integer
        For i = 1 To r.Columns.Count
            For j = 1 To r.Rows.Count
                On Error Resume Next
                r(j, i).Value = 1 - r(j, i).Value
                On Error GoTo 0
    End Sub

    • Edited by Viorel_MVP Monday, December 23, 2019 4:38 PM
    Monday, December 23, 2019 4:37 PM