• Change sign of cell value based on another cell content

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Change sign of cell value based on another cell content

    Author
    Topic
    #507949

    I download financial accounting data from a website weekly. Instead of positive and negative values, the numbers are all positive in a column with another column telling me whether it is an Expense or Income. I transfer this data to my finance spreadsheet for budgeting, cost analysis, etc.
    I need to change the Expense values to a negative number based on the word ‘Expense’ in the next column. The number of values downloaded is variable.

    Any help?

    Viewing 1 reply thread
    Author
    Replies
    • #1588594

      If your numbers are in column A and the indication is in column B, try this (adjust as needed for where the data resides):

      Code:
      Sub NegateExp()
          Dim LastRow As Long
          Dim i As Long
          LastRow = Range("A" & Rows.Count).End(xlUp).Row
          For i = 1 To LastRow
              If Range("B" & i).Value = "Expense" Then
                 Range("A" & i).Value = -Range("A" & i)
              End If
          Next i
      End Sub
      
      • #1588598

        Well, that was easy… works great. Thanks much. Seems easy after seeing it…

        • #1588678

          ..we can make it more complicated if you want to:

          Sort the data so all the Expenses are in one block.
          Enter -1 into a spare cell.
          Copy this cell with Ctrl-C
          Then, select the range of expense values to be converted, and use Paste Special>Multiply
          ..then re-sort your data back into it’s original order.

          zeddy

    • #1588756

      From an accounting perspective you should have two columns and positive numbers – there is no negative money that I know of. 🙂

      cheers, Paul

      • #1588770

        Hi Paul

        ..my wallet is full of negative money.

        zeddy
        (actually, I just have photos of the kids, to remind me where my money used to be)

    Viewing 1 reply thread
    Reply To: Change sign of cell value based on another cell content

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: