Help with VBA

darko757

New Member
Joined
Dec 27, 2018
Messages
6
Hello,

I am making a macro which would create a "Result" sheet based on the "Input" sheet. In the "Input" sheet there is data containing columns Employee#, First Name, Monday am, Monday pm, Tuesday am, Tuesday pm, Wednesday am, Wednesday pm, Thursday am, Thursday pm, Friday am and Friday pm. Rows are Employees. In that table, employees are putting "y" or "n" for specific day and specific type of day (if one employee has all "y" and "n" at Tuesday pm, that means he/she is not working only at Tuesday pm).

The "Result" sheet contains columns Employee#, Start Date, Time off type (0.5 or 1 i.e. half of the day or full day absence), and Note which contains text like "Does Not Work On Mondays" or "Does Not Work On Friday pm".

"Result" sheet is being created in the following way: if employee #27 puts "n" for Monday pm and "n" on both Tuesday am and pm, that means that employee will have 2 rows per week in the "Result" sheet. First row the F column would be "Does Not Work On Monday pm" and second would be ""Does Not Work On Tuesdays". Since this macro is for the purpose of the whole year of 2019, the first working day would be Wednesday, 2nd of January. So, in this employee's case, the row with "Monday pm" will have 07.01.2019. in the start date and the row with "Tuesdays" should have 08.01.2019. Those rows should copy until the end of the year (third row is 15.01. in the Date column, fourth row is 16.01, fifth row is 22.01, sixth row is 23.01 etc.)

The problem I can't solve is the thing about the end of the year. When all entries (rows) are created for one employee, the same should be done for the next employee (right below the last entry from the previous employee). I can't think of a good constraint which would track the last day of the year (depending of the non-working days of the employee, the last day of the year could be 31.12.2019 (tuesday), but it can also be 25.12, 26.12, 27.12 or 30.12. (monday). which is creating a big problem for me. At the start of making this macro, I have simply put the constraint

If Left(Cells(l - 1, 2), 5) = "31.12" Then

which is working just fine if the current employee's non-working day is Tuesday. If he/she WORKS on Tuesdays, VBA goes crazy and just goes to the infinite loop. I would appreciate so much if anyone could help or at least give some ideas for this constraint.

I know this post is surely confusing but trust me that there is no better way of explaining this silly Excel file (I didn't make it and I can't change the format of neither sheets).

Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Maybe something like this
Code:
If DateValue(Cells(l - 1, 2)) >= #12/25/2018# And DateValue(Cells(l - 1, 2)) <= #12/31/2018# Then
 
Upvote 0
And still, that won't work because it can happen that someone will not work on for example 27.12, 30.12 and 31.12...
 
Upvote 0
One more thing, I am doing this as a Freelance job for one client so I would really appreciate any help on this matter as the deadline is approaching (31st dec 2018.)
 
Upvote 0
And what if my date format is set to 31.02.2019?

I just assumed that when working with dates, the code would be within the confines of the system settings for national formats. It is much easier for the user to comply with the application conventions than to try and force the application conventrions to comjply with the user'r preferences.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top