+ Reply to Thread
Results 1 to 7 of 7

Copying cells to another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2008
    Location
    London
    MS-Off Ver
    2007
    Posts
    66

    Copying cells to another sheet

    I would like to be able to copy a group of cells from sheet 1 to sheet 2 or 3 based on a value in another cell on sheet 1 eg
    sheet 1
    If Cell A1 = 24, A2=London Road (this make up an address), A5= omit

    If A5 = omit I would like the address copied to sheet 2
    If A5 = Complete I would like it copied to sheet 3

    I have 1600 address to go through.

    Thanks

    Vetequk
    Last edited by Vetequk; 03-15-2009 at 09:00 AM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Copying cells to another sheet

    Hi

    And where does the next block of data start / end? Is each block 5 rows long and every 5th line has your test requirement?

    Perhaps add a small example file with 4 or 5 items, or if your data has different formats/ number of rows, an example of each, and how this example data should be output.

    rylo

  3. #3
    Registered User
    Join Date
    05-21-2008
    Location
    London
    MS-Off Ver
    2007
    Posts
    66

    Re: Copying cells to another sheet

    rylo
    I have attached a sample file.
    What I am trying to do is filter the list so I can copy all the address that have been omitted to the list sheet, but I only need the the information in the 1st, 2nd & 5th column copied over.


    Thanks

    Vetequk
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying cells to another sheet

    Your macro seems to work as is for "omit", so you just need to add the "complete" references and another sheet. If the 3rd sheet were called "complete", your macro could expand like so:
    Sub Omit()
    Dim lastrow As Long
    lastrow = Sheets("test").UsedRange.Rows.Count
    Application.ScreenUpdating = False
    
        Range("A8:I" & lastrow).AutoFilter
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7, Criteria1:="Omit"
        Range("A25:B64").Copy
        Sheets("List").Range("A3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("G25:G" & lastrow).Copy
        Sheets("List").Range("C3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("B79").Select
        Application.CutCopyMode = False
        ActiveSheet.Range("A8:$I" & lastrow).AutoFilter Field:=7
        
        Range("A8:I" & lastrow).AutoFilter
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7, Criteria1:="Complete"
        Range("A25:B64").Copy
        Sheets("Complete").Range("A3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("G25:G" & lastrow).Copy
        Sheets("Complete").Range("C3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("B79").Select
        Application.CutCopyMode = False
    '    ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    05-21-2008
    Location
    London
    MS-Off Ver
    2007
    Posts
    66

    Smile Re: Copying cells to another sheet

    JBeaucaire
    Thanks for the reply which has been very helpful, but once the data has been filtered the first cell reference could anthing from A9 to last row. I am trying to find away to assign the cell under A8 (once the data has been filtered) to a string.
    This is the code so far:-
    Dim FC As String
    Dim lastrow As Long
    lastrow = Sheets("test").UsedRange.Rows.Count
    Application.ScreenUpdating = False
    
        Range("A8:I" & lastrow).AutoFilter
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7, Criteria1:="Omit"
        ActiveSheet.Range("A8").Select
        ActiveCell.Offset(1, 0).Select
        FC = ActiveSheet.ActiveCell
        Range(FC & ":B64").Copy
        Sheets("List").Range("A3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("G25:G" & lastrow).Copy
        Sheets("List").Range("C3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("B79").Select
        Application.CutCopyMode = False
        ActiveSheet.Range("A8:$I" & lastrow).AutoFilter Field:=7
    Application.ScreenUpdating = True
    I have highlighed the area that I think is the problem


    Thanks

    Vetequk

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying cells to another sheet

    I think this solves the problem, also solves the problem of what to do if there are NO "omit" or "complete" results.:
    Sub OmitComplete()
    Dim lastrow As Long
    lastrow = Sheets("test").UsedRange.Rows.Count
    Application.ScreenUpdating = False
    
        Range("A8:I" & lastrow).AutoFilter
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7, Criteria1:="Omit"
        On Error GoTo Reset1:       'If there are no "omit" values
        Range("A9:B" & lastrow).SpecialCells(xlCellTypeVisible).Copy
        Sheets("List").Range("A3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("G9:G" & lastrow).SpecialCells(xlCellTypeVisible).Copy
        Sheets("List").Range("C3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("B79").Select
        Application.CutCopyMode = False
        
    Reset1:
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7
        
        Range("A8:I" & lastrow).AutoFilter
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7, Criteria1:="Complete"
        On Error GoTo Reset2:       'If there are no "Complete" values
        Range("A9:B" & lastrow).SpecialCells(xlCellTypeVisible).Cells.Copy
        Sheets("Complete").Range("A3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("G9:G" & lastrow).SpecialCells(xlCellTypeVisible).Copy
        Sheets("Complete").Range("C3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Sheets("test").Range("B79").Select
        Application.CutCopyMode = False
            
    Reset2:
        ActiveSheet.Range("A8:I" & lastrow).AutoFilter Field:=7
    Application.ScreenUpdating = True
    End Sub

  7. #7
    Registered User
    Join Date
    05-21-2008
    Location
    London
    MS-Off Ver
    2007
    Posts
    66

    Re: Copying cells to another sheet

    JBeaucaire
    Thanks that worked great

    Vetequk

+ 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