ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change the Values in a Column to 'Minus' If Q (https://www.excelbanter.com/excel-programming/453092-change-values-column-minus-if-q.html)

Sean[_17_]

Change the Values in a Column to 'Minus' If Q
 
I have 8 columns. My values are in Column 7. These are all 'Positive' values, but the detail in Column D indicates if these values are actually negative or positive (that seems odd, but thats my data layout)

I want to replace values with a minus, if the text "Invoice" or "Debit Note" is in Column D on the same row

E.g. Currently Column G shows 8,536.50, but Column D for this Row has "Invoice" detailed, thus I wish to change the value in Column G to -8,536.50

My data I extract from a system, so the length of it may vary depending on when I extract it

Claus Busch

Change the Values in a Column to 'Minus' If Q
 
Hi Sean,

Am Thu, 26 Jan 2017 02:49:16 -0800 (PST) schrieb Sean:

I have 8 columns. My values are in Column 7. These are all 'Positive' values, but the detail in Column D indicates if these values are actually negative or positive (that seems odd, but thats my data layout)

I want to replace values with a minus, if the text "Invoice" or "Debit Note" is in Column D on the same row

E.g. Currently Column G shows 8,536.50, but Column D for this Row has "Invoice" detailed, thus I wish to change the value in Column G to -8,536.50

My data I extract from a system, so the length of it may vary depending on when I extract it


try:

Sub Test()
Dim LRow As Long, i As Long

With ActiveSheet
LRow = .Cells(.Rows.Count, "G").End(xlUp).Row
For i = 2 To LRow
Select Case .Cells(i, "D").Value
Case "Invoice", "Debit Note"
.Cells(i, "G") = -1 * .Cells(i, "G")
End Select
Next
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016

[email protected]

Change the Values in a Column to 'Minus' If Q
 
Bingo Claus, works perfect, thanks again



All times are GMT +1. The time now is 05:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com