Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Excel VB question

  • 19-09-2007 12:11PM
    #1
    Closed Accounts Posts: 20


    Hi

    Im a C/C++/Java man who is stuck on a problem in Excel. I have a spreadsheet
    which contains amongst other things, a column of cells containing data of the form:

    16/09/2007[17:21]
    16/09/2007[17:22]
    16/09/2007[17:23]

    What I want to do is maintain a counter of cells whose time value is between 8 am and 8pm and produce that in a messagebox.

    Could anyone point me in the right direction please?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 901 ✭✭✭EL_Loco


    you should be able to find examples of reading in cell values easily enough,

    declare 2 arrays,
    use the split function using [ as the delimiter into the first array,
    you'll get 16/09/2007 and 17:21] as the elements

    split the 2nd element 17:21] using : as the delimiter into 2nd array
    you'll have 17 and 21] as elements

    check the first element, in this case 17, to see if it's >=8 and <=20
    increment a counter if it is.

    If you want code examples let me know, off to lunch now ;)


  • Registered Users, Registered Users 2 Posts: 5,398 ✭✭✭DublinDilbert


    In these sort of situations the "VarType( )" call is very useful, it allows you see what the VB equivalent of the excel data is..

    If you call the VarType on the cell it will tell you how the data is being stored, hence you can figure out how to read it...

    http://www.csidata.com/custserv/onlinehelp/VBSdocs/vbs218.htm


    Set s4 = ThisWorkbook.Sheets(Sheet3)
    if VarType(s4.Cells(row, col + i).value) = vbString then

    elseif VarType(s4.Cells(row, col + i).value) = vbDouble then

    endif


Advertisement