• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Differences between 2 out of 3 cells depending on whats filled.|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Differences between 2 out of 3 cells depending on whats filled.|General Excel Questions & Answers|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Differences between 2 out of 3 cell…
sp_PrintTopic sp_TopicIcon
Differences between 2 out of 3 cells depending on whats filled.
Avatar
Ben Davis-gibbons
London United Kingdom

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
October 18, 2018
sp_UserOfflineSmall Offline
1
October 18, 2018 - 12:49 am
sp_Permalink sp_Print

Hi,

**During this question i shall be referring to cells within the spreadsheet attached**

N.b. I am using a VBA shortcut to insert the dates.

Basically i want to figure out the duration between 2 of the cells depending on whether one of them is filled or not. I want G5 to contain the difference between E5 and D5 UNLESS there is a date in F5 then i want the duration between F5 and D5.

I've tried the following code from my very basic knowledge and googling but it keeps coming up with an error. 

=sum(IF((AND(ISBLANK(F5), NOT(ISBLANK(E5))), "=sum(E5-D5)", "=sum(F5-D5)")))

With error

"there's a problem with this formula. Not trying to type a formula? When the first character is an equal (=) or minus(-) sign, Excel thinks it's a formula:

-you type: =1+1, cell show: 2

To get around this, type an apostrophe ( ' ) first:

-you type: '=1+1, cell shows =1+1"

 

Any help will be greatly appreciated, a walk-through of why my formula isn't working and why yours does what also be appreciated.

 

Thank you in advance.

Ben

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catherine Lorenzo

New Member
Members
Level 0
Forum Posts: 1
Member Since:
December 13, 2015
sp_UserOfflineSmall Offline
2
October 18, 2018 - 10:41 am
sp_Permalink sp_Print

Hi Ben,

There's no need to use the equals sign or quotes in your formula, and you don't need the SUM() function either .  Try this:

=IF(ISBLANK(D5), "", IF(ISBLANK(E5), "No Response Yet", (IF(ISBLANK(F5), E5-D5, F5-D5))))

 

This formula checks D5 for a value.  If blank, then nothing is returned.

If D5 has a time, the next IF checks E5 for a value.  If blank, the cell shows the statement, "No Response Yet".

If D5 and E5 have times, the next IF checks F5 for a value.  If blank, the difference between E5 and D5 is shown, otherwise, the difference between F5 and D5 is shown.

Hope that helps!

sp_AnswersTopicAnswer
Answers Post
Avatar
Kevin Junk
Member
Members
Level 0
Forum Posts: 23
Member Since:
October 18, 2018
sp_UserOfflineSmall Offline
3
October 18, 2018 - 1:02 pm
sp_Permalink sp_Print

Hi Ben

Looking at your question and spreadsheet I assume that you want the time elapsed between E5 and D5 if F5 is blank, otherwise you want the time elapsed between F5 and D5. The following formula will do that:

=IF(ISBLANK(F5),E5-D5,F5-D5)

The formula uses the ISBLANK function to test if cell F5 is blank. If that is true it calculates the difference between E5 and D5, otherwise (ie. F5 is not blank) it calculates the difference between F5 and D5.

I usually incorporate a couple of other tests just in case:

=IF(OR(ISBLANK(F5),LEN(F5)=0,F5=""),E5-D5,F5-D5)

This also uses the LEN function to test if the length of a cell is zero, and tests if the cell is a zero-length string.

See this for a discussion of the ISBLANK function.

You could also incorporate more logic to test if the contents of the cells are true date/times, but since you are entering the data with a VBA shortcut you should incorporate any necessary validation/formatting in that.

Avatar
Ben Davis-gibbons
London United Kingdom

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
October 18, 2018
sp_UserOfflineSmall Offline
4
October 18, 2018 - 8:32 pm
sp_Permalink sp_Print

Hi Both,

Thank you both so much for the help. Both ways worked perfectly fine, i however opted to use Catherine's code due to the addition of the no response yet being added in (nice touch!).

I would have marked each as being the answer if that was the button i pressed, i pressed useful answer (Which they both are) but for some reason they've got that button set to make that the reply the answer of the question.

 

Thanks again,

Ben

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Catalin Bombea, Kim Knox, Nada Perovic, Othman AL MUTAIRI
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Bhuwan Devkota
Kathryn Patton
Maria Conatser
Forum Stats:
Groups: 3
Forums: 24
Topics: 6222
Posts: 27293

 

Member Stats:
Guest Posters: 49
Members: 31916
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.