Forum Discussion
HotBlue
Jul 30, 2020Copper Contributor
Multiple actions of an IF test
Is there a way to implement 2 actions based on the results of an IF test? For example: IF($G6=$K6,... for a true result I would like to implement both copying $G6 to $M6 and set $K6="". I have tr...
- Jul 30, 2020
This is not possible with a formula. A formula returns a value in the cell that contains the formula; it cannot perform other actions. What you want requires VBA:
- Right-click the sheet tab.
- Select 'View Code' from the context menu.
- Copy the code listed below into the worksheet module.
- Close the Visual Basic Editor.
- Save the workbook as a macro-enabled workbook (.xlsm).
- Make sure that you allow macros when you open the workbook.
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("G6,K6"), Target) Is Nothing Then If Range("G6").Value = Range("K6").Value Then Application.ScreenUpdating = False Application.EnableEvents = False Range("M6").Value = Range("G6").Value Range("K6").ClearContents Application.EnableEvents = True Application.ScreenUpdating = True End If End If End Sub
wumolad
Jul 30, 2020Iron Contributor
Hi HotBlue
I believe what you can do is to type in the formula in M6, so that M6 gets the value of G6 when G6 is equal to K6.
In which case, this formula will suffice.
IF($G6=$K6,$G6,"")
This assumes you want M6 value to be blank if G6 is not equal to K6.
However, the second aspect is dicey as I am not sure you intend to type in any formula in K6, given that K6 is part of the logical test in the IF test. In this case, you might need to use VBA to resolve this.
Cheers