Andrew1995

New Member
Joined
Jan 16, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Dear friends
i am in need of some help. i am quite new and learning. i have done some work on it but dont know how to continue now. So basically i have a ''master'' called sheet that has a list of students from A6 TO A36 and their student ids from B6 to B36 and from C6 to C36 to have their unique password. the columns D E and going on have there subjects and grades. so what i want to do is as follows:
1) After i add the details of the students and their grades, all their details to be copied to a new sheet for each student in a new workbook automatically as in the example below. (one workbook with new sheet for every student) i will attach the master sheet and a new student sheet for example purposes.
2)After the new workbook is created i want when i open it to have all the details hidden and a search box to appear directly. each student must add their unique id and there unique password to show their sheet only and to not have any other options to do.


master sheet.png
STUDENT SHEET.png
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This code should create the sheets with the names as the tabs.

Then need to adapt it to loop through and create what is to be completed to each sheet?

VBA Code:
Sub Students ()

    Dim xRg As Excel.Range
    Dim wSh As Excel.Worksheet
    Dim wBk As Excel.Workbook
    Set wSh = ActiveSheet
    Set wBk = ActiveWorkbook
    Application.ScreenUpdating = False
    Dim Lastrow as Long

Lastrow = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row

    For Each xRg In wSh.Range("A6:A" & Lastrow)
        With wBk
            .Sheets.Add after:=.Sheets(.Sheets.Count)
            On Error Resume Next
            ActiveSheet.Name = xRg.Value
            If Err.Number = 1004 Then
              Debug.Print xRg.Value & " already used as a sheet name"
            End If
            On Error GoTo 0
        End With
    Next xRg
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
just tested it. it works but it creates the new sheets in the same workbook. i need the new sheets to be created in a new workbook. thanks any ideas
 
Upvote 0
Hi Andrew,
Have you found the solution for your school project? I'm a fresher at the New Mexico State University and need help cause I'm a complete noob... I've also contacted Jon Acampora from ExcelCampus, but still waiting for the reply.
 
Upvote 0
just tested it. it works but it creates the new sheets in the same workbook. i need the new sheets to be created in a new workbook. thanks any ideas

Hi,
I just amended your code. Check it out now. All the worksheets should be now created in newly created workbook.

Code:
 
Upvote 0
Hi,
I just amended your code again. I did it previously on mobile and attached it to the post, however it did not save. Checki it out now.

VBA Code:
Sub Students ()

    Dim xRg As Excel.Range
    Dim wSh As Excel.Worksheet
    Dim wBk As Excel.Workbook
    Dim nWb as Workbook
   
    Set wBk = ActiveWorkbook
    Set wSh = wBk.ActiveSheet
  

    Application.ScreenUpdating = False
    Dim Lastrow as Long

Lastrow = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
    
    Set nWb = Workbooks.Add
   
    For Each xRg In wSh.Range("A6:A" & Lastrow)
        With nWb
            .Sheets.Add after:=.Sheets(.Sheets.Count)
            On Error Resume Next
            ActiveSheet.Name = xRg.Value
            If Err.Number = 1004 Then
              Debug.Print xRg.Value & " already used as a sheet name"
            End If
            On Error GoTo 0
        End With
    Next xRg
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,030
Members
448,940
Latest member
mdusw

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