+ Reply to Thread
Results 1 to 9 of 9

referencing a range of cells within a formula of a macro relative to a different cell

  1. #1
    Registered User
    Join Date
    06-11-2015
    Location
    United States
    MS-Off Ver
    2016
    Posts
    26

    referencing a range of cells within a formula of a macro relative to a different cell

    Hello,

    I just started getting into macros, and am finding wonders with introducing it to my scheduling spreadsheet i have for work. I have a calendar with all my employees work shifts for the month within it. I am trying to now introduce a new feature that allows me to see the number of employees i have working at any given time during that specific day while i am creating the schedule (that way i know i am scheduling the correct amount of people at each hour). I figured out how to do it one way, but it requires changing the macro every time for every day of the year. I just did the first 14 days of the year, and am realizing that this will take forever (so tedius) if i have to do it for every other day. So I'd like to find a way where i can create just a few macros instead of 365.

    this is what i currently have: (see attachment for clarification)currentMacro.png

    basically the way i have it right now is that when i select the macro button for each day (there is a separate macro for each day) it fills out all the information from AE4:AF4, AE5:AF5, AF7:AF54 by this formula =COUNTIFS(JANW1D1IN,"<="&AE7, JANW1D1OUT, ">"&AE7)
    as you can see i named all the ranges of clock in and out dates based on which box of the month they were in...

    what id rather do is some how call those ranges based on some offset of the cell that the macro button is at( the box of the day that i want to calculate the count per hour of the day). Does that make sense? I feel like if i was able to do this, i could use the same macro for the entire month rather than having to have a separate macro for each day.

    im guessing id need a total of 12 macros this way since each month i want the results to display in the same area as the month.. so in february, id want the macro to show the results on lines AE112:AF112 etc...

    is this possible? if so? can someone help me figure this out so i don't have to copy paste and edit 365 macros, and create all those range names 730 :O

    if you need more of an explanation i will try to explain better, but hopefully this is enough for at least someone to help think of other ways. I have been trying on my own for a few days and couldn't figure it out.. Thanks in advance to anyone that takes the time to read and reply!
    Last edited by Jgray805; 12-11-2019 at 11:14 PM.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    Welcome to the forum,

    Quote Originally Posted by Jgray805 View Post
    ...
    1. So I'd like to find a way where i can create just a few macros instead of 365
    2. what id rather do is some how call those ranges based on some offset of the cell that the macro button is at (the box of the day that i want to calculate the count per hour of the day).
    3. i could use the same macro for the entire month rather than having to have a separate macro for each day
    4. id need a total of 12 macros this way since each month i want the results to display in the same area as the month
    5. id want the macro to show the results on lines AE112:AF112 etc
    6. so i don't have to copy paste and edit 365 macros, and create all those range names 730 :O
    ...
    hello Shakespeare ...

    So ... what exactly do you want to achieve ?

    If you have many buttons to which you want to link a macro/macros, for example you can do it this way (for Microsoft Excel controls):
    Please Login or Register  to view this content.
    or alternatively ... if you want to operate multiple buttons with one macro, for example you can do it this way:
    Please Login or Register  to view this content.
    See example in the attachment:

    1. Initial state - buttons without macro/macros assigned
    2. You run the macro "A1_assign_macro_ABC_to_buttons"
    3. Then you press the buttons
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-11-2015
    Location
    United States
    MS-Off Ver
    2016
    Posts
    26

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    Thanks for the reply Porucha Vevrku..

    that's not exactly what i was referring to, but definitely something that will save time if i do end up going the route of bruit forcing the document (needing different macros for each button)

    my goal is to be able to view the number of employees working per hour on each day. i thought i would do this by having a macro button at the bottom of each day and it displaying the results to the right side of the calendar (see attached picture in my original post).
    I was hoping to get help on writing a code that i could use in my macros that would minimize the need for 365 macros (one for each day). Since i initially wrote my post yesterday, I went ahead and finished the first month.

    I feel like I should be able to condense it though so i don't have all these macros to accomplish what i want.. right now i have 37 macros for just for January, 1 for each of the possible 37 boxes that days can show up in any given month.
    each macro looks like this, with of course the names switched accordingly...

    below is an example of one of the 37 macros...januarys 2nd week, and the 1st day of week 2 (left most box,sunday)

    Please Login or Register  to view this content.
    January works perfect!! It works just the way I want from the surface level; however, i really don't want to have to bruit force months February - December like this not just because of the time consumption but also because i am eager to learn a more efficient way.

    my thoughts in my head are telling me that i need to somehow call the names relatively rather than by their actual names that i gave them. (doing so, i feel like that would allow me to use the same macro for multiple days..maybe not one for the whole year, but possibly just one or 2 per month, or even 1 per week) But, i don't know how to call certain cells relatively from the box that it is in while at the same time displaying the results in a range of absolute cells.

    does that make sense? Any thoughts?
    Last edited by Jgray805; 12-12-2019 at 01:16 PM.

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    It seems to me that, you make your life difficult, with "these named ranges" (defined names). "This" can be done without these - below is an example.
    Press "Make buttons", then press any "D day" button - selection is only for range visualization.
    Using this scheme, you can extract specific ranges of cells to/for formulas.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-11-2015
    Location
    United States
    MS-Off Ver
    2016
    Posts
    26

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    OH WOW about how to create all those buttons at one time.. That will definitely save me hours!! THANKS! I am going to go try to code this to my specific sheet using your example, thanks!

    I need those buttons to do something different though. I need them to auto populate the # of employees working per every half hour of the day. (not just add up the hours worked per shift per employee) I want this count per half to populate on the column just to the right of the calendar.
    (see my attachment for what i am talking about visually)

    I think I'm having trouble figuring it out because the buttons will be in different locations each time, and where i want the information to be displayed will be in an absolute location. I am going to reread and reread ur code to see if maybe the answer is in there and i am just not getting it yet.

    NOTE: the way January functions at the surface level in my spreadsheet is perfect!! It's exactly the way i want it, but i just know recreating all the other months the way i have it set up will take hours and hours...
    (not as many now that i know the creating button trick.. but still as of now because i feel like i need a different macro per button? I will keep trying to figure it out, but if you have any ideas or extra help i would appreciate more insight. Thank you!
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    The number of macros can be kept to a minimum, they don't have to be dozens.
    Below is an example of how you can handle most of your needs with one macro, just an example, because it has not been tested for all cases and it certainly won't work properly from 'A' to 'Z'. However, it shows the direction in which you can go.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    06-11-2015
    Location
    United States
    MS-Off Ver
    2016
    Posts
    26

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    holy cow!! that's it!! I've been tweaking it just slightly all night and really analyzing all the code you wrote out and it all actually now starting to make sense.

    Thank you so much for all your help!! It's amazing how you can actually refer to all those cells without actually having to name them. :D

    After i got everything the way i wanted just a little bit ago, i was able to duplicate February's page in just about 10 minutes. and it worked perfect!!

    I'm going to change the rest of the months tomorrow, and i will let you know how it turns out. i'm sure those will go even faster now that i know what all the syntax means.

    Thank you again so much!! I'm definitely going to sleep well tonight!

  8. #8
    Registered User
    Join Date
    06-11-2015
    Location
    United States
    MS-Off Ver
    2016
    Posts
    26

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    I just wanted to follow up and let you know that i have finished the whole year now. You saved me so much time. Thank you again for helping me figure this out!

    I learned a lot too from you. Knowing what you taught me will be so useful for future things I create too! I added some conditional formatting to the cells that shower the hour count which is going to save me a lot of $$ in payroll by not over scheduling and stressing when i accidentally under schedule in the future.

    Now i am going to move to my next step of the document and start adding employee availability so I don't accidentally schedule people on their requested time off.

    Take Care,

    Jason

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: referencing a range of cells within a formula of a macro relative to a different cell

    Ok, I'm glad

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Absolute to Relative Cell Referencing Macro Help!
    By Cele in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-26-2012, 04:51 AM
  2. Referencing relative cells (current row)
    By jirib in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2011, 02:46 PM
  3. Macro for creating named ranges from relative referencing
    By parodytx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2008, 01:00 AM
  4. Macro to capture cell value then use it for a relative range selec
    By PZ Straube in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-13-2005, 04:05 AM
  5. [SOLVED] macro relative referencing
    By harriet in forum Excel General
    Replies: 5
    Last Post: 02-15-2005, 10:06 AM
  6. Relative referencing in macro won't work
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2005, 10:06 AM
  7. relative referencing cells in formulas
    By YOYO in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2005, 11:28 AM
  8. [SOLVED] Relative Indirect Formula Referencing?
    By Damian in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-07-2005, 02:19 AM

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