Excel VBA - Summary table fori Vacant and Occupied

  • Dears,


    Good day! I would like to make a summary of my table using excel vba.


    From attached file, i have a number of rows which specify the name/number of rooms in col B and at col C mentioned number of occupied rooms.


    If the value in col C, for example show as "Occupied 2" it will take the first 2 rows and make the summary table which is shown on col E to J. if it is "Occupied 8" it will occupy the 8 rows.. and so on.


    if the next rows (after occupying the number of rows mentions) is vacant, it will count the number of vacant until it reach the row with values again.


    This will have a loop until the last rows in col B and create the summary table.


    Thanks in advance.


    br,
    Ivan

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Thank richdj4.


    i prefer to use VBA, since i have a 2000 rows to work on, which is on different sheets.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    The table will work for a million or so rows, you just have to set the named ranges Rooms and remarks accordingly. If you'd really prefer VBA, I'll try and knock something up tonight

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Try this


    Working file attached, click button to run code and create summary.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Dear KjBox, could you please check it again, i just edit the table, but it didn't show the right output.


    Thanks.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Hi,


    OK it goes wrong if the first group of rooms are all occupied, must have missed that scenario in my testing.


    Replace the code with this:

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    OK, I think (certainly hope!) this should cover all room occupancy/groups scenarios

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Just thought of another scenario, where the first occupied room is a higher Room Number than 1, this will cover that scenario too.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Hopefully run out of scenarios by now! Try this

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    lol, you'll have to rerun the code every time you make a change, or add summary() to the worksheet change event.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    True, but the OP requested VBA, up to him how he chooses to use the code.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Excel VBA - Summary table fori Vacant and Occupied


    Simply

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!