+ Reply to Thread
Results 1 to 23 of 23

VBA Find highest number in a daily range

  1. #1
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    VBA Find highest number in a daily range

    I have this sheet (which is generated by my Solar Inverter)

    Which produces the following (2 columns)

    date-time kWh-generated
    for example

    2022/11/09 17:00 13.29

    in a 5 or 6 min interval for a whole week (this attached sheet is only a small part of it (total lines original sheet is over 2000))

    Now I am looking for the highest number kWh on a day to day basis
    (I marked it in green on the sheet)

    BUT

    it must ignore numbers from 7:00pm till 7:00am so only pick the highest number for that day in the period from 7am - 6:xxPM as Solar is producing from approx 7am onwards till 5-6pm only.

    Is this possible with VBA?

    TiA
    Attached Files Attached Files
    Last edited by iammike; 11-14-2022 at 03:58 AM.

  2. #2
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    What also would help if I can find the highest number (day per day) in the range let's say 7pm-8pm.

    In that range (time frame) the highest number of the day should be known, but a problem is sometimes the inverter logs in a 5 min but the start time is different so maybe the range can be

    2022/11/08 19:04
    2022/11/08 19:09
    2022/11/08 19:14
    2022/11/08 19:19
    2022/11/08 19:24
    2022/11/08 19:29
    2022/11/08 19:34
    2022/11/08 19:39
    2022/11/08 19:45

    or

    2022/11/09 19:03
    2022/11/09 19:08
    2022/11/09 19:14
    2022/11/09 19:19
    2022/11/09 19:24
    2022/11/09 19:29
    2022/11/09 19:34
    2022/11/09 19:39
    2022/11/09 19:44

    So you see the times aren't the same on a day to day basis.
    Last edited by iammike; 11-14-2022 at 04:06 AM.

  3. #3
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    If not possible via VBA of course via a Formula or another way would be absolutely great as well

    TiA

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Find highest number in a daily range

    See if this is how you want it.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    Almost perfect, 7th is correct.

    but on the 8th, the highest is 10.93 but script says: 9.95

    and on the 9th the highest is 13.29 but script produces 9.88

  6. #6
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    Solved it

    changed time from 7am - 7pm to 7pm - 8pm, because then for sure the highest number is available

    Thx a Bunch, really appreciated.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Find highest number in a daily range

    OK, try insert one line in bold
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    Yes works! Absolutely great.

  9. #9
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    It works perfectly, but Would it be very hard to adjust if for example the date/time is still in column A but the data (other data) I am looking for is in (for example Column Q?)

    There are more columns in those particular sheet, the last column with interesting data is in Column BL

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: VBA Find highest number in a daily range

    an alternative to vba is power query

    Please Login or Register  to view this content.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  11. #11
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    OOoh wow, that would do me as well because there are a LOT more columns (up to "BL") in that XLS.

    Will this work for my version?? About Excel says: Version 2210 (build 15726.20202 Click to Run)

    Yes it does

    Excel 2016 or newer, where Power Query capabilities are integrated within the Data tab. More information
    Last edited by iammike; 11-15-2022 at 02:31 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Find highest number in a daily range

    When you ask question with the sample workbook, it should follow the same data types/structure as your actual data,
    in order to avoid unnecessary back and forth/guess work.

    So you will need to upload a sample workbook again.

  13. #13
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    Getting an error:

    Expression.Error: We couldn't find an Excel table named 'Table1'.
    Details:
    Table1
    Tried to rename to the name of the sheet but no go

  14. #14
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    @jindon.

    My Bad sorry. Will do that of course.

    it's just a BIG XLS lots and lots of data, for these couple of days it's over 1,5 MiB in size and lots of info in it I will never need.

    Thx again, and sorry again

  15. #15
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: VBA Find highest number in a daily range

    Tried to rename to the name of the sheet but no go
    Do not rename the sheet, you need to make sure the table you are loading to excel has the same name. Either change the name of your table or change the Mcode to the name of your table.

  16. #16
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    Quote Originally Posted by alansidman View Post
    Do not rename the sheet, you need to make sure the table you are loading to excel has the same name. Either change the name of your table or change the Mcode to the name of your table.
    Aah I need to convert the Data to a Table first

    Did that and,

    on the 8th, the highest is 10.93 but it comes up with 9.95
    on the 9th the highest is 13.29 but it comes up with 9.88
    etc

  17. #17
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: VBA Find highest number in a daily range

    My apologies. In the first attempt, I did not change the data type to decimal and left it as mixed type. Here is the new Mcode.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    @jindon.

    Here is the whole Sheet (only 3 days worth) with all the Info I am looking for (highest values)

    I marked the columns in Green
    Attached Files Attached Files

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Find highest number in a daily range

    try chnge to
    Please Login or Register  to view this content.
    Last edited by jindon; 11-16-2022 at 11:05 PM.

  20. #20
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    WOW yes absolutely totally works

    One more question please, would it be possible to add the (finished) data to the same worksheet every time? Now it creates a separate sheet every time it runs. No problem if it overwrites the data in that new sheet.

    Thx a lot.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Find highest number in a daily range

    Code in post #19 has been edit as per your post #20.

  22. #22
    Registered User
    Join Date
    02-19-2020
    Location
    SE-Asia
    MS-Off Ver
    2019
    Posts
    98

    Re: VBA Find highest number in a daily range

    Oooh Wow, I wish I could add more reputation.

    Really really appreciated

    And for my understanding

    If I want more columns, I just add them to this list?

    Please Login or Register  to view this content.
    Correct?

    Thx again.

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Find highest number in a daily range

    Yep, correct, and you can even change the order EXCEPT Date/Time column i.e. 1.

+ 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. Find the highest number
    By smd7m in forum Excel General
    Replies: 4
    Last Post: 02-09-2021, 04:34 PM
  2. [SOLVED] Find highest version number for each material number
    By keld.strobel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-06-2015, 07:08 AM
  3. [SOLVED] How2 find number in range and return that number or if doesn't exist then the next highest
    By Crawfinator1 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-06-2014, 08:52 AM
  4. [SOLVED] Formula to select the highest number, and the lowest and find out the range
    By Nero_slk in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-14-2013, 07:56 AM
  5. Find highest number of sales in a date range and show seller and sale number
    By audiofreak in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-06-2012, 03:34 AM
  6. VBA code to find highest and 2nd highest number based in criteria
    By Michael007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2011, 08:38 AM
  7. Replies: 1
    Last Post: 01-09-2006, 09:30 AM

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