If function

dci1966

New Member
Joined
Jul 27, 2018
Messages
8
Please can you help an excel novice with a question on how to write a formula using the IF function to detect certain text in a column of a spreadsheet and then to turn numbers in three other columns into negatives if that text is true? Thank you :)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to the Board!

Let's say that you are looking for the word "dog" in A1, and if it exists, take the negative value of the entry in cell B1.
Then that formula would look like this:
Code:
=IF(ISNUMBER(FIND("dog",A1)),0-B1,B1)

Is that what you are after?
 
Upvote 0
Welcome to the board dci1966

What is in the other 3 columns?
- values?
- formula?
 
Upvote 0
Welcome to the Board!

Let's say that you are looking for the word "dog" in A1, and if it exists, take the negative value of the entry in cell B1.
Then that formula would look like this:
Code:
=IF(ISNUMBER(FIND("dog",A1)),0-B1,B1)

Is that what you are after?

Sorry, maybe I should have explained it better! I actually have 3 columns of numbers which I have extracted from an accounts package but the credits haven't come through as negatives so they are throwing off my totals - I want to look for all the credit notes (marked "CRN" in column A) and then turn the positive numbers in columns C,D and E to negative, is that even possible?!
 
Upvote 0
Sorry, maybe I should have explained it better! I actually have 3 columns of numbers which I have extracted from an accounts package but the credits haven't come through as negatives so they are throwing off my totals - I want to look for all the credit notes (marked "CRN" in column A) and then turn the positive numbers in columns C,D and E to negative, is that even possible?!
Any cell can either have a hard-coded value, or a formula, but not both at the same time.
So to change existing hard-coded values in cells, that will require VBA. Is that something you are willing to use?
If so, are the cells EXACTLY equal to "CRN", or is part of a larger string?
 
Last edited:
Upvote 0
If your values in column A were exactly equal to "CRN", here is VBA code that would do what you want:
Code:
Sub MyNumFix()

    Dim lr As Long
    Dim r As Long
    Dim c As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column A
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows of data
    For r = 1 To lr
'       Check to see if column A equals "CRN"
        If Cells(r, "A") = "CRN" Then
'           Negate values in columns C-E
            For c = 3 To 5
                Cells(r, c) = 0 - Cells(r, c)
            Next c
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Any cell can either have a hard-coded value, or a formula, but not both at the same time.
So to change existing hard-coded values in cells, that will require VBA. Is that something you are willing to use?
If so, are the cells EXACTLY equal to "CRN", or is part of a larger string?

LOL definitely not up to VBA!!!!!! cells are exactly CRN or INV..........
 
Upvote 0
LOL definitely not up to VBA!!!!!!
You don't need to understand it or know how to write it in order to use it.
Follow these instructions to insert and run the VBA code that I wrote for you: https://www.ablebits.com/office-addins-blog/2013/12/06/add-run-vba-macro-excel/

The only way I can think of to do it without VBA is to set-up three formulas (like the ones I posted in my original response), then do a Copy -> Paste Special Values to copy the results of those formulas over the original data. Then you can delete the formulas and are left with what you want.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top