Use one cell to conditionally set the value of another cell

Koeilik

New Member
Joined
Jan 30, 2023
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi. So I have a situation where I would like to manually input data OR have a formula calculate a value for a certain cell.
The situation is as per the table below and is for a travel logbook. The formula in B4 is obviously not correct but describes what I want to do in excel terms.

Start odometer kmEnd odometer kmDistance traveled
[A2][B2][C2]= if(Not(IsBlank(A2)) & Not(IsBlank(B2)), set(C2, B2 - A2))

If there is no value in A2 and B2 then nothing should happen to C2. If there are values in A2 and B2 then C2 should be set to the difference between them. This way Column C can be manually filled in incase the driver forgot to check the odometer readings at the start/end of each trip (as is often the case).

Example of execution below:

Start odometer kmEnd odometer kmDistance traveled
{user entered value in C2; A2 & B2 are blank so no calculation is made}
8652087156636{A3 & B3 is not blank; C3 is calculated and set according to B3 - A3}

I thought of leaving Column C without a formula to allow for user input. If values in Columns A and B are inserted, a separate cell (e.g. column D as per tables above) will remotely change the value in column C. Is there a way to achieve this?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You had the right idea as far as the logic, but you can't leave column C blank and still have it calculate a value, unless you use VBA. In C2 use this formula:

Excel Formula:
=IF(AND(A2<>"",B2<>""),B2-A2,"")


and copy down. When would you want to allow user input there?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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