+ Reply to Thread
Results 1 to 13 of 13

How To Convert Cell Contents To A Number Using IF

  1. #1
    Registered User
    Join Date
    09-06-2022
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    14

    How To Convert Cell Contents To A Number Using IF

    Hello!

    If I have cell contents that represent a shift schedule, and I want to convert it to the number of hours it represents (seen below in bold numbers), how can I do that using IF?

    Example of contents:

    8:30 AM - 4:30 PM 8
    2:00 PM - 4:00 PM 2
    8:00 AM - 11:00 AM 3
    11:00 AM - 4:00 PM 5
    6:30 AM - 10:30 AM 4
    8:45 AM - 2:45 PM 6
    8:30 AM - 4:30 PM 8
    8:00 AM - 3:00 PM 7
    Attached Files Attached Files
    Last edited by coltonyyz; 09-06-2022 at 12:32 PM. Reason: To make it more clear

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: How To Convert Cell Contents To A Number Using IF

    Welcome tp the forum.

    Why using IF? Are other solutions welcome? Is this TWO columns of data or just ONE?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    09-06-2022
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: How To Convert Cell Contents To A Number Using IF

    Oh, any method is welcomed! I figured IF would be easiest by simply creating another table using the formula. I'm all ears! I've updated my post to format it like a table to illustrate better what I need.

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: How To Convert Cell Contents To A Number Using IF

    with Power Query

    Column1.1 Column1.2 Column2 Subtraction
    08:30:00
    16:30:00
    8
    8
    02:00:00
    16:00:00
    2
    14
    08:00:00
    11:00:00
    3
    3
    11:00:00
    16:00:00
    5
    5
    06:30:00
    10:30:00
    4
    4
    08:45:00
    14:45:00
    6
    6
    08:30:00
    16:30:00
    8
    8
    08:00:00
    15:00:00
    7
    7


    Please Login or Register  to view this content.
    yellow is your calculation, why 2 ?

  5. #5
    Registered User
    Join Date
    09-06-2022
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: How To Convert Cell Contents To A Number Using IF

    Thanks for pointing out the typo! It should have said PM - which would make the calculation 2.

    With the programming code (I don't know what to call it, but the "Let Source =" part), where would I place this? Is this VBA?

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: How To Convert Cell Contents To A Number Using IF

    This is M-code , Power Query

    https://docs.microsoft.com/en-us/power-bi/

    would be fine if do that by yourself from the beginning using my code as example


    btw
    Column1
    Column1.1 Column1.2 Subtraction
    8:30 AM - 4:30 PM
    08:30:00
    16:30:00
    8
    2:00 AM - 4:00 PM
    02:00:00
    16:00:00
    14
    8:00 AM - 11:00 AM
    08:00:00
    11:00:00
    3
    11:00 AM - 4:00 PM
    11:00:00
    16:00:00
    5
    6:30 AM - 10:30 AM
    06:30:00
    10:30:00
    4
    8:45 AM - 2:45 PM*
    08:45:00
    14:45:00
    6
    8:30 AM - 4:30 PM
    08:30:00
    16:30:00
    8
    8:00 AM - 3:00 PM
    08:00:00
    15:00:00
    7
    Attached Files Attached Files
    Last edited by sandy666; 09-06-2022 at 12:44 PM.

  7. #7
    Registered User
    Join Date
    09-06-2022
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: How To Convert Cell Contents To A Number Using IF

    I've installed Power-bi but have no experience what-so-ever with it.

    I have 190 columns of data with 37 rows for each. I was hoping I could simply do an IF statement to convert the cell contents to the number they represent. This is to calculate total hours, where the rows are employees, the columns are the days.

    How did you paste your table in with that formatting so quickly? When I copy and paste from excel, it doesn't do any of the formatting, just straight text.

  8. #8
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: How To Convert Cell Contents To A Number Using IF

    Excel 365 contain Power Query by default so you no need Power BI

    select your source table
    Data tab
    From Table
    it will open Power Query window with your original table
    the rest is in the code

    if you want to use my code in PQ qindow find Advanced Editor then paste code there

    btw, I did it with your example but not with 190 columns
    Last edited by sandy666; 09-06-2022 at 01:04 PM.

  9. #9
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How To Convert Cell Contents To A Number Using IF

    Try this one

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How To Convert Cell Contents To A Number Using IF

    Or with a UDF

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-06-2022
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: How To Convert Cell Contents To A Number Using IF

    Quote Originally Posted by JEC. View Post
    Try this one

    Please Login or Register  to view this content.
    Thank you for this! As much as I appreciate sandy666's suggestion (and I did try to incorporate it into my spreadsheet, this reply I think will work easier for me!

    I did get an error for line 9 on my uploaded sample worksheet. 8:45 AM - 2:45 PM gave me the #VALUE! error... any idea how this can be fixed so that it calculates the correct hours?

  12. #12
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: How To Convert Cell Contents To A Number Using IF

    There is a space behind 2:45 PM. Remove that first

  13. #13
    Registered User
    Join Date
    09-06-2022
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: How To Convert Cell Contents To A Number Using IF

    Thank you! Yes, this was the problem! And your formula I was able to copy it again for each 190 columns and it fill my table in, in its entirety! Thank you so much for this formula!!!

    If a mod is reading this, I want to mark JEC's reply as the answer to my problem! I'm sure the other's would work too, but JEC's was the easiest; for me at least!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Convert the contents of a cell to a column
    By Yaghoub61 in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 02-08-2022, 12:32 AM
  2. [SOLVED] Convert contents of cell created by a formula back to its contents.
    By Pallando_II in forum Excel General
    Replies: 2
    Last Post: 07-27-2016, 06:35 PM
  3. [SOLVED] Convert cell contents before compare
    By Gandalf2524 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2014, 06:20 PM
  4. [SOLVED] Convert cell contents to range
    By jgrogan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-17-2006, 04:35 AM
  5. How to convert cell contents
    By Robert Judge in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-13-2006, 03:10 PM
  6. How to convert cell contents?
    By Robert Judge in forum Excel General
    Replies: 0
    Last Post: 06-08-2006, 09:50 AM
  7. [SOLVED] How do I convert a cell(s) from the formula to it's contents?
    By ZZBC in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-30-2006, 11:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1