+ Reply to Thread
Results 1 to 9 of 9

Time range cell selection change

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Time range cell selection change

    Hello,

    I tried to look for a previous thread concerning this and I am not able to find anything, so hopefully this hasn't already been asked. I have a production report that uses time ranges to fill data, and the time ranges are in column 16. I need to pull the data from each hour, and I want to set the range between the hour in B16 and C16, C16 and D16 etc. and then post the data in the relevant cells in that column. My main question is how to have the code treat every range seperately instead of having to create a sub for each. Here is what I have so far:
    Please Login or Register  to view this content.
    dtStartDate and dtEndDate are the values that need to change for each hour, and for the most part they will just go down the row one by one(C16-N16, P16-AA16)

    I am relatively new to VBA programming, any help or explanation would be greatly appreciated.

    Thank you very much.

  2. #2
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Re: Time range cell selection change

    I forgot to mention that I also need this done on 5 other worksheets, "MON PROD", "TUES PROD", "WED PROD", THURS PROD", "FRI PROD" and "SAT PROD". Is there any way to do this from one line of code, or does it have to be done for each sheet? I am trying to make all of the querys happen at the press of a single button.

  3. #3
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Time range cell selection change

    Hi Mike,

    You can run your code with a loop, and use the loopnumber to fill the columnnumber used in the cells function.
    You should also use it in the displaying of the data, otherwise it will overwrite eachother.
    I assume there is another part of the code?
    If not, where do you want the output pasted for e.g. the start/end B16/C16

  4. #4
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Re: Time range cell selection change

    There is more code, but I am editing it from a previous spreadsheet so most of it really isn't relavant right now. I need to get the amount of units produced per hour, and to do this I was going to subtract the last unit in one hour from the last unit in the next and then post the difference to the 10th row in that column. I understand this is probably hard to understand without seeing the rest of the code, so I will work on getting the loop in place and then post the rest.

  5. #5
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Time range cell selection change

    Hi Mike,

    Try something like this then

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Re: Time range cell selection change

    Thanks for your quick reply. I've had a lot of time off and a lot of other projects going on so I am just getting back to this. I am having trouble with the loop. I didn't give you all of the code that I should have. It is telling me that there is a next without for, but as far as I can tell it should be working. Any suggestions?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Re: Time range cell selection change

    I just realized there are two "next" statements, but removing either doesn't help.

  8. #8
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Re: Time range cell selection change

    And this is the code that fills the data. I need this to spread the data from the previous code accross column 10.

    Please Login or Register  to view this content.
    Thanks for any help. There is more to it, but I think that once I can figure out how to loop all of this the rest will be easy.

  9. #9
    Registered User
    Join Date
    12-17-2012
    Location
    Lansing, MI
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    9

    Re: Time range cell selection change

    I am going to mark this as solved since you gave me all you could with the info I provided, but I created another thread at http://www.excelforum.com/excel-prog...html?p=3094704 with more details. Thanks for helping as much as you have!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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