Formula to look at column C and Row A if match find cell and deduct of total how to do?

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi I hopeyou can help me please, I want a formula to look at a selected date and area,and if match to deduct the number what has been inputted in cell AC5 and enter thenew total in matching cell.
In columnsB2 to R2 I have the ‘dates’.
In Rows A3to A18 I have the ‘areas’.
In rows/columnsB3 to R18 I have numbers.

In Cell AC3I have a dropdown list with ‘dates’
In Cell AC4I have a dropdown list for ‘areas’.
In AC5 thisis where we enter a number.

What I wantis when a date is selected in AC3 and a area is selected in AC4 then a numberis inputted in AC5 I then want the corresponding cell to be updated In rows/columnsB3 to R18,

So forexample if I choose 04/09/2019 as a date and LOND as an area then enter anumber 5, I want the computer to find 04/09/2019 and LOND then if currently thenumber in that cell is 7 I want it to -5 and update the new number to 2.

Hope thismakes sense and you can help me with the formula.

Would it belike a IF or MATCH formula?
 
hi I did ctrl g again and pasted in Application.EnableEvents = True under immediate hop this I correct?, but i still didnt work
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello,

You could test following

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, j As Long, errorFound
On Error GoTo errorFound
If Target.Address <> "$AC$6" Then Exit Sub
Application.EnableEvents = False
    i = Application.Match(Range("AC3"), Range("A1:A18"), 0)
    j = Application.Match(Range("AC4"), Range("A2:R2"), 0)
    
    Cells(i, j).Value = Cells(i, j).Value - Range("AC6").Value
                
errorFound:
Application.EnableEvents = True
End Sub

Hope this will help
 
Upvote 0
Re,

By the way ... regarding your formula in cell AC5 ...

Would recommend following

Code:
=IFERROR(INDEX($A$1:$R$18,MATCH(AC3,$A$1:$A$18,0),MATCH(AC4, $A$2:$R$2, 0)),"")
 
Last edited:
Upvote 0
Hi thank you so much this works great, is there any way to clear AC3 to AC6 after the update? thank you again.
Please n you advise what is different with the formula as well for reference? Is It more secure?
 
Upvote 0
Hi,

Glad you could fix your problem ...

To clear cells, you can have

Code:
Range("AC3:AC4,AC6").ClearContents

Using the Index / Match gives you more flexibility ... and IfError will prevent you from having #N/A ... whenever you are clearing input cells ...

Hope this explains ...
 
Upvote 0
thank you where would I put the code above in the coding? iferror sounds a lot better as well I will use this more often :)
 
Upvote 0
Glad you like the Iferror function ...:wink:

Regarding the modified macro

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, j As Long, errorFound
On Error GoTo errorFound
If Target.Address <> "$AC$6" Then Exit Sub
Application.EnableEvents = False
    ' Determine Row # and Column #
    i = Application.Match(Range("AC3"), Range("A1:A18"), 0)
    j = Application.Match(Range("AC4"), Range("A2:R2"), 0)
    
    ' Adjust the Intersection cell Value by substracting Input in AC6
    Cells(i, j).Value = Cells(i, j).Value - Range("AC6").Value
    
    ' Clear all Input cells
    Range("AC3:AC4,AC6").ClearContents
                
errorFound:
Application.EnableEvents = True
End Sub
 
Upvote 0
Hi I just amended the code to clear contents to only clear AC6 but excel keeps on crashing now after I press enter when I have inputted a number in AC6
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,227
Members
453,025
Latest member
Hannah_Pham93

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