Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Excel VB question

Options
  • 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 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 Posts: 5,379 ✭✭✭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