+ Reply to Thread
Results 1 to 8 of 8

Macro to change a date using the +/- keys.

  1. #1
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Macro to change a date using the +/- keys.

    I admittedly know very little in the way of Macros/VBA, but I hope this can be done by borrowing some your expertise.

    I have set up a balance sheet for one of my less computer proficient friends. Overall, they love the setup, but they hate having to type in the date for every entry. Apparently, Quickbooks has an option through which you can use a + or a - to change the date up one day or down one day respectively.

    My request is the following: I would like for Excel to automatically copy the date from the previous row once a new row is selected. Next, using this information as a basis, I would like the user to be able to press + or - to change the date.

    I will attach a sample balance sheet as a reference.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Hi, Bas. You mention in the spreadsheet that the user would like to use the + twice to change the date. The problem with that is that Excel recognizes that as a formula, which causes an error. However, this is possible using a single + or -. The one thing I don't really like about this is if you use ENTER after the + or -, it automatically moves the cursor to the next row, which then populates that date field as well (since the cell in the next row is selected). However, this can be changed in the options so that the cursor moves a different way (e.g. right).
    Please Login or Register  to view this content.
    HTH

    Jason

  3. #3
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Jason:

    Thanks for the help. I would just like to clarify something, because I seem to have been unclear. I do not necessarily want to press + twice to change the date; rather, I would like to use plus to increase the date by 1. (So, if I need to increase the date by two days, I press + twice, 3 days: press + 3 time, etc).

    I think the ideal setup I would like (if possible) is something along the lines of the Quickbooks setup. Specifically, the date would be visible, and as I press +, it will automatically increase by one day, while remaining visible. If this cant be done with the + sign, since its a formula key, I don't mind using letters ("a" to increase date by one day, "z" to decrease by one day).

    Thanks again for your time.

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    The procedures I posted will work using the + or - keys. However, it will not work unless the cell value changes (i.e. user presses ENTER, TAB, or uses arrow keys). I am not aware of any event procedures for keydown on the sheet itself.

    Jason

  5. #5
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Thanks for your help, Jason. I modified that macro somewhat so that "a" and "z" cause the change and if either is pressed more than once, it will add by that amount.

    I would like to ask one other question: What if I modified my request slightly? Again, I wonder if this can be done. Can I possible add a new column (before column A) with control buttons. Macros would be assigned to the control buttons, so that if it is clicked, it will automatically add (if the add is clicked) and subtract (if the subtract is clicked). If that can be done, I think it would be a perfect substitute to merely pressing the + or - keys. Also, is there anyway to have these control buttons float so that they are next to the active row (if not, it is no big deal)?

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Yes, using control buttons would actually make the code a bit simpler, something like:
    Please Login or Register  to view this content.
    I would recommend using a UserForm to include these 2 command buttons, and set it modeless. Unfortunately, I am not familiar with modeless user forms (since my work uses Office 97, and user forms cannot be set modeless in this version), so I do not know how to make it stay next to the selection.

    Jason

  7. #7
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Jason:

    Thanks a lot for your help. When I get home tonight, I will play around with the code you have set up for me, and see if I can get it to go Modeless (google, here I come).

    Thanks for the time.

  8. #8
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    After some consideration, I decided that two command buttons were probably not the best idea; instead, I chose a spin button. I was able to manipulate the code that Jason gave me, along with some codes that I found elsewhere, and I have for the most part what I need. There is only one thing that somewhat annoys me.

    When I was working with the Command Buttons, in the properties menu, I had the option to disable "Take focus on Click." I dont want the command button to take the focus. I cannot find this option for the spin button. Is it possible? Do I need to use new code?

    Here is what I have so far:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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