+ Reply to Thread
Results 1 to 9 of 9

Copy a range of cells in multiple sheets

Hybrid View

G-Star Copy a range of cells in... 05-14-2012, 06:12 AM
AlvaroSiza Re: Copy a range of cells in... 05-14-2012, 12:34 PM
G-Star Re: Copy a range of cells in... 05-14-2012, 01:29 PM
AlvaroSiza Re: Copy a range of cells in... 05-14-2012, 01:54 PM
G-Star Re: Copy a range of cells in... 05-14-2012, 02:47 PM
AlvaroSiza Re: Copy a range of cells in... 05-14-2012, 03:03 PM
G-Star Re: Copy a range of cells in... 05-14-2012, 03:15 PM
AlvaroSiza Re: Copy a range of cells in... 05-14-2012, 03:24 PM
G-Star Re: Copy a range of cells in... 05-14-2012, 03:30 PM
  1. #1
    Registered User
    Join Date
    05-14-2012
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    5

    Copy a range of cells in multiple sheets

    Hi there,

    I am trying to automatize a series of action to facilitate the procedure that I use to mark students` essay.
    Here what I would like to do:

    I have a "StudentList" sheet containing students ID, Student Names and Marks and a "MarkingCriteria" sheet containing student details, marker details and assessment criteria.

    After entering the student list I would like to be able to create a MarkingSheet for each student, assign the sheet the name of student and copy the contents of the MarkingCriteria. I need that the student`s detail (name) in the Marking Criteria match the Sheet name`. Further I need that the Final mark calculated for each student return the "StudentList" in the column "Mark".

    The only thing that I managed to do as a novice VBA user, was to create a CommandBotton that create one sheet for each student. However I don know how to insert the MarkingCriteria in this sheets...


    I enclosed my file...if someone wish to help me.

    Thanks

    G-Star
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Copy a range of cells in multiple sheets

    Click the button and tell me if this is what you were after:

    Marking Sheet Template.xlsm

    The code:

    Sub StudentMarks()
    
    Dim ws1 As Worksheet
    Dim wsTemplate As Worksheet
    Dim rngName As Range
    Dim rngStudents As Range
    Dim calcMode As Long
    
    Set ws1 = ActiveWorkbook.Sheets("StudentList")
    Set wsTemplate = ActiveWorkbook.Sheets("Student")
    
       With Application
          calcMode = .Calculation
          .Calculation = xlCalculationManual
          .ScreenUpdating = False
          .EnableEvents = False
       End With
    
          With ws1
             Set rngStudents = .Range("C2", .Range("C2").End(xlDown))
          End With
    
          For Each rngName In rngStudents
             wsTemplate.Copy After:=Sheets(Sheets.Count)
             Set wsCurr = ActiveSheet
                wsCurr.Name = CStr(rngName)
                wsCurr.Range("B2").Value = rngName
          Next
    
        With Application
          .Calculation = calcMode
          .ScreenUpdating = True
          .EnableEvents = True
       End With
    
    End Sub
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Registered User
    Join Date
    05-14-2012
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Copy a range of cells in multiple sheets

    Thanks Alvaro! That`s brilliant!

    The only missing instruction is the one that copies the Final Mark from each Student`s Marking sheet into the StudentList sheet (in the Mark column). In this way I can get the overall stats on the performance of my class.

    G-Star

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Copy a range of cells in multiple sheets

    Would you be open to me adding a 'Get Marks' button to set alongside the existing? The grades are not available at run time of the routine I provided, so I think it makes sense to separate them. Let me know.

  5. #5
    Registered User
    Join Date
    05-14-2012
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Copy a range of cells in multiple sheets

    Ok, I think this would work. The final mark is the value that comes out from the cell c20 in the "student" sheet.

    G-star

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Copy a range of cells in multiple sheets

    Ok, so you will click the top Create button to get your worksheets created. Once you have completed your marks, you will click the red 'Get Marks' button, which will send the "C20" value for each student to the Marks column corresponding to their name on the 'StudentList' worksheet.

    For a quick test, give Nathan a mark and then click the red button. You will see his mark appear with zeros for all other students (because you have not completed theirs yet).

    Spreadsheet Here >> Marking Sheet Template.xlsm

    'GetMarks' code:

    Sub GetMarks()
    
    Dim ws1 As Worksheet
    Dim rngName As Range
    Dim rngStudents As Range
    Dim calcMode As Long
    
    Set ws1 = ActiveWorkbook.Sheets("StudentList")
    
       With Application
          calcMode = .Calculation
          .Calculation = xlCalculationManual
          .ScreenUpdating = False
          .EnableEvents = False
       End With
    
          With ws1
             Set rngStudents = .Range("C2", .Range("C2").End(xlDown))
          End With
    
          For Each rngName In rngStudents
             rngName.Offset(0, 1).Value = Sheets(CStr(rngName)).Range("C20").Value
          Next
    
       With Application
          .Calculation = calcMode
          .ScreenUpdating = True
          .EnableEvents = True
       End With
    
    End Sub
    Last edited by AlvaroSiza; 05-14-2012 at 03:05 PM.

  7. #7
    Registered User
    Join Date
    05-14-2012
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Copy a range of cells in multiple sheets

    Ok, you are genius! THANKS! ...and fast. there is only a little problem...all the formulas now work only if I activate the cells where they are located and press enter. Is it normal?

    G-Star

  8. #8
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Copy a range of cells in multiple sheets

    Interestingly, the calculation mode did not tick back to automatic. Hmmmm. I have forced Automatic upon termination of the code, which should get you back to what you are used to.

    One more time here >> Marking Sheet Template.xlsm

    In the future and to extend your general excel knowledge, what you experienced is the result of an xlCalculationManual setting. What you are used to is xlCalculationAutomatic. You can always change these settings via:

    Office Button >> Excel Options >> Formulas >> 'Calculation Options' >> 'Workbook Calculation' >> 'Automatic'

  9. #9
    Registered User
    Join Date
    05-14-2012
    Location
    Sheffield
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Copy a range of cells in multiple sheets

    Ok, Thanks for the tip. And thanks for the help!
    I am trying to understand VBA...I have been probably too ambitiuos with my marking Sheet, but I will go through your code to learn something.

    ...Everything works perfectly now!

    G-Star

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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