Results 1 to 3 of 3

Copy a range based on a cell value

Threaded View

  1. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy a range based on a cell value

    Hello tuke016,

    Welcome to the Forum!

    The following macro has been added to the attached workbook. There is button on "Sheet1" to run the macro. This will copy each row to worksheet "A+", "A", "B+", etc. depending on the value in column "M" of "Sheet1".
    
    Sub CopyToSheetsByGrade()
    
        Dim DstWks As Worksheet
        Dim N As Long
        Dim R As Long
        Dim Rng As Range
        Dim Wks As Worksheet
        
            Set Rng = ActiveSheet.Range("A1").CurrentRegion
            
            For R = 1 To Rng.Rows.Count
            
                Set DstWks = Worksheets(Rng.Cells(R, "M").Text)
                N = DstWks.Cells(Rows.Count, "A").End(xlUp).Row
                
                If N = 1 Then
                   If WorksheetFunction.CountA(DstWks.Range(Rng.Rows(1).Address)) > 0 Then N = N + 1
                Else
                   N = N + 1
                End If
                
                DstWks.Rows(N).Resize(ColumnSize:=Rng.Columns.Count).Value = Rng.Rows(R).Value
                
            Next R
            
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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