Trouble Looping through list to generate individual timecards

alexthebaker

New Member
Joined
Sep 24, 2013
Messages
1
Hello!

I'm trying to generate individual timecards for people based on data entered into a data range for a single week. I have a timecard worksheet that is filled with values from data on another sheet. I want to be able to create a copy of each persons' timecard and put them all into a new workbook.

I've made it so the timecard sheet is filled with one person's data based on their name appearing in a lookup cell and using VLOOKUP formula's to fill out the rest of the timecard. The data range also has a first column in which I'd like to be able to mark each line with an "x" to specify whether to include it when generating all the timecards.


I'm trying to figure out how to accomplish this but am very new to VBA and can't seem to figure it out from the pieces of code I've found. I think it needs to do something like this:


1. Select the first row in the data range marked with an "x" (sheet "Setup" range named "Crew").
2. Set the value in the VLOOKUP reference cell to the person's name in same row as step 1 (their name is in column 3 of the "Crew" range). The VLOOKUP reference cell is "D6" on worksheet "Home".
3. Create a new workbook with the week ending date (value in cell "K4" on worksheet "Setup").
4. Copy the now filled out timecard (sheet "Preview Card") to a new workbook as values.
5. Rename the sheet in the new workbook to the person's name (cell "D6" on worksheet "Home").
6. Select the next row and repeat for each line in the "Crew" range marked with an "x".


I would also like to protect each sheet in the new workbook so that only cell "DA1" is locked and the rest are editable. I'd also like to save the file relative to where the source file is (it'll be used by both Mac and PC users).


The Preview Card sheet is protected with a macro so that the other script can copy the worksheet but the user can't touch anything (I hope I did this right):
Code:
Private Sub Workbook_Open()
Sheets("Preview Card").Protect Password:="1234", UserInterFaceOnly:=True
Sheets("Preview Card").EnableSelection = xlUnlockedCells
End Sub

The little bit of code I have right now is:

Code:
Sub Generate()
    
    Sheets("Preview Card").Copy
    Cells.Select
    Selection.Copy
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
    Sheets("Preview Card").Name = person.Value
    Range("G5").Select


    ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & "Generated TimeCards" & Application.PathSeparator & Format(Range("BR6"), "mm") & "-" & Format(Range("BR6"), "dd") & " - " & Range("F7") & ".xlsx", FileFormat:= _
        xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWorkbook.Close


End Sub

I'm using Excel for Mac 2011 but would love for this to work with on a PC as well. Any help or direction would be greatly appreciate (and awesome!) This is my first time posting so I hope I'm putting this in the right place :)

Thanks,
Alex
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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