Results 1 to 3 of 3

Thread: VB Editor question - help with project

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    1

    VB Editor question - help with project

    Hello,

    I am using the editor within Excel, not VB itself to create this so Im unsure if this is the correct place to post but be gentle as it is my first post on these forums.

    Anyway here goes, I have come up with a new project for work, fairly simple but something I am not entirely familiar with. The extent of my knowledge in VB is upto IF and WHEN statements, some DIM and searching functionality but thats about it.

    The project itself, involves recording reference numbers as an input from the user in a text box, when the user hits submit it then records that number in a cell on a spreadsheet along with a timestamp in an adjacent cell. The user then continues this function and it keeps recording the numbers and timestamps in cells below the last, keeping a history etc.

    Another function I want to include is when the user hits a back arrow button, it will show the last reference number they submitted along with the timestamp, repeated clicking of the backbutton will continue to show the prior reference and timestamp and so on. Similarly a forward button to go back to the most recent and then stopping with a messagebox when theyre viewing the most recent.

    Although not essential I would also like to include a search function where they can input a time and it will show as a result, the closest timestamp/reference number to the time they input.

    I know it sounds like im asking for help in the entire project and not just a particular piece of coding, but to start off with I would simply just be grateful if someone could tell me the snippet of code that allows me to record the reference they input into a cell, and then the next one goes into the cell below and so on and so on.

    Thanks.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: VB Editor question - help with project

    Welcome to VBForums

    Thread moved to the 'Office Development/VBA' forum... note that while it certainly isn't made clear, the "VB Editor" in Office programs is actually VBA rather than VB, so the 'VB6' forum is not really apt

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB Editor question - help with project

    assuming you are using a userform to input the data

    at the very top of the userform code page
    vb Code:
    1. dim lastrecord as long

    in the userform initialize event
    vb Code:
    1. lastrecord = cells(rows.count, 1).end(xlup).row    ' find last record on sheet from previous
    in the save button click event (or what ever you want to use to save record)
    vb Code:
    1. cells(lastrecord + 1, 1).value = textbox1   ' reference to column 1
    2. cells(lastrecord + 1, 2).value = now     ' timestamp
    3. lastrecord = lastrecord  + 1          ' increment counter

    to use the arrow keys, you can put code in the keydown (or keyup) event of the textbox that recognises the arrow keys

    you can use excels find method to find records by timestamp

    the above code samples do not specify which sheet to work with and always assumes the activesheet, it is better practice to always fully qualify the range (specify which sheet)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width