Results 1 to 4 of 4

Thread: More than just copying and pasting

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    More than just copying and pasting

    Ok, I have tried to explain what I am trying to do with no success. I am going to post my excel document instead, I believe it will be be easier. If you open this workbook, on the manager input sheet, you will see a button that say something about running the macro. Click it and it will take you to the performance grid sheet and put all of the names on the grid where they are supposed to be.

    Now:
    As you will see there is a table at the bottome that is not filled out. What I want the macro to do is put all of the people in each colored zone, into the appropriate column in the table below the grid. PLEASE give me some hints here, I have tried multiple things, and they do not work. Of couse I could simply do a copy and paste of each cell, but that would look bad.

    The end result will be a performance grid that is locked for editing, but with a distribution table below it that is editable.

    Thanks in advance!!!!!
    Attached Files Attached Files

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: More than just copying and pasting

    Here's a re-worked version. I made the following changes.

    1/ Added some lookup tables in a new sheet.
    2/ Added 3 formula colums to the "Manager Input" sheet.
    3/ Used Named Ranges for lookup tables and for the 'colour' reports.
    4/ Rewrote the code as follows.

    Let me know what you think.
    I will give more detail on how the changes work tomorrow, need sleep now....
    VB Code:
    1. Option Explicit
    2.  
    3. Sub DKBuildReport()
    4.  
    5. Dim rngName As Range
    6. Dim sName As String
    7. Dim lRowNum As Long
    8. Dim lColNum As Long
    9. Dim sColour As String
    10. Dim rngPerfGrid As Range
    11. Dim rngGridCell As Range
    12. Dim rngColour As Range
    13.    
    14.     '-----------------------------------------------
    15.     'Set Initial references and Clear Reports
    16.     '-----------------------------------------------
    17.  
    18.     'Set the reference to the Result Grid
    19.     Set rngPerfGrid = ThisWorkbook.Worksheets("Performance Grid").Range("B7:K11")
    20.    
    21.     'Reset the Performance Grid
    22.     With rngPerfGrid
    23.         .ClearContents
    24.         .Rows.AutoFit
    25.     End With
    26.    
    27.     'Reset the Colour Reports
    28.     With ThisWorkbook.Worksheets("Performance Grid")
    29.         .Range(.Range("rngPINK").Offset(1, 0), .Range("rngPINK").End(xlDown)).ClearContents
    30.         .Range(.Range("rngYELLOW").Offset(1, 0), .Range("rngYELLOW").End(xlDown)).ClearContents
    31.         .Range(.Range("rngORANGE").Offset(1, 0), .Range("rngORANGE").End(xlDown)).ClearContents
    32.         .Range(.Range("rngGREEN").Offset(1, 0), .Range("rngGREEN").End(xlDown)).ClearContents
    33.         .Range(.Range("rngDARKORANGE").Offset(1, 0), .Range("rngDARKORANGE").End(xlDown)).ClearContents
    34.         .Range(.Range("rngPALEBLUE").Offset(1, 0), .Range("rngPALEBLUE").End(xlDown)).ClearContents
    35.         .Range(.Range("rngDEEPBLUE").Offset(1, 0), .Range("rngDEEPBLUE").End(xlDown)).ClearContents
    36.  
    37.     End With
    38.    
    39.     'Start with the first name
    40.     Set rngName = ThisWorkbook.Worksheets("Manager Input").Range("A3")
    41.    
    42.     Do
    43.        
    44.         '-----------------------------------------------
    45.         'Get inputs
    46.         '-----------------------------------------------
    47.        
    48.         'Get the employee name
    49.         sName = rngName.Value
    50.         'The Grid Row
    51.         lRowNum = rngName.Offset(0, 16)
    52.         'The Grid Column
    53.         lColNum = rngName.Offset(0, 17)
    54.         'And the Colour
    55.         sColour = rngName.Offset(0, 18)
    56.        
    57.        
    58.         '-----------------------------------------------
    59.         'Populate Main Grid
    60.         '-----------------------------------------------
    61.        
    62.         'Set the target cell range in the main grid
    63.         Set rngGridCell = rngPerfGrid.Cells(lRowNum, lColNum)
    64.        
    65.         With rngGridCell
    66.             'Either add to the target cell or
    67.             'The next cell to the right
    68.             If .RowHeight < 400 Then
    69.                 .Value = .Value & sName & Chr(10)
    70.             Else
    71.                 .Offset(0, 1).Value = .Offset(0, 1).Value & sName & Chr(10)
    72.             End If
    73.            
    74.             'If lRowNum = 2 Then Stop
    75.            
    76.             'Adjust the row height
    77.             .Rows.AutoFit
    78.            
    79.             If .RowHeight <= 60 Then
    80.                 .RowHeight = 60
    81.             ElseIf .RowHeight < 400 Then
    82.                 .RowHeight = .RowHeight + 2
    83.             End If
    84.         End With
    85.        
    86.        
    87.         '-----------------------------------------------
    88.         'Populate Colour Grid
    89.         '-----------------------------------------------
    90.        
    91.         'Set a reference to the colour Header
    92.         Set rngColour = ThisWorkbook.Worksheets("Performance Grid").Range(sColour)
    93.        
    94.         With rngColour
    95.             If .Offset(1, 0).Value = "" Then
    96.                 .Offset(1, 0).Value = sName
    97.             Else
    98.                 .End(xlDown).Offset(1, 0).Value = sName
    99.             End If
    100.         End With
    101.        
    102.        
    103.         '-----------------------------------------------
    104.         'Move to the next cell
    105.         '-----------------------------------------------
    106.        
    107.         Set rngName = rngName.Offset(1, 0)
    108.    
    109.     Loop Until rngName.Value = ""
    110. End Sub
    Attached Files Attached Files
    Last edited by DKenny; May 2nd, 2006 at 11:19 PM.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    Re: More than just copying and pasting

    first of all, that is amazing. you really need to set up a tip jar.

    I only have one question:
    Where are the "rngPALEBLUE", "rngORANGE", etc defined? when I changed them to things like "rngTopPerformer" (I also changed the controls sheet to reflect the change), it started bombing out.

    This really is incredible. I could just leave it as the colors, but I want to understand what it is doing and I don't understand how it knows where the color ranges are that it gets the data from, and then which color range in the rngcolour to put it in. Or for that matter, where rngColour is?

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: More than just copying and pasting

    Where are the "rngPALEBLUE", "rngORANGE", etc defined?
    They are define on the worksheet as named ranges.
    Insert-->>Name-->>Define will show you a list of all the names that have been created and what ranges they refer to.

    Also have a look in the Excel help file for "Define named cell references or ranges".

    Named ranges are really useful in Excel, I use them all the time in formulas, validation, code, etc...

    when I changed them to things like "rngTopPerformer" (I also changed the controls sheet to reflect the change), it started bombing out.
    Changing the label (top cell) of the range has no effect, you would need to define this as a new range. I would leave the range names as are in both the code and the sheet and just change the labels.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width